Loading data in external table SQLLoader - oracle

I want to crate external table based on datafile, but I got error. I use whitespace to delimit my record but this doesn't work . Yes I created directory and gave read and write permissions than I created my external table . However when I selected it I got an error:
ORA-29913: error in executing ODCIEXTTABLEOPEN callout
ORA-29400: data cartridge error
My external table is :
create table nflteams_ext (
ACR varchar2(4),
NAME varchar2(20))
organization external
(
type oracle_loader
default directory ext_tab_data
access parameters (
records delimited by newline CHARACTERSET US7ASCII
fields terminated by whitespace
missing field values are null
(ACR varchar2(4),
NAME varchar2(20))
)
LOCATION ('NFL_Teams.dat')
)
REJECT LIMIT UNLIMITED NOPARALLEL;
data file:
NO New Orleans Saints
PIT Pittsburgh Steelers
IND Indianapolis Colts

The problem is solved . I used char instead of varchar2 in the lower section of my external tablecreation also I delimeted by '/n'.
CREATE TABLE nflteams_ext
(acr VARCHAR2( 4),
name VARCHAR2(20))
ORGANIZATION EXTERNAL
(TYPE ORACLE_LOADER
DEFAULT DIRECTORY ext_tab_data
ACCESS PARAMETERS
(RECORDS DELIMITED BY NEWLINE CHARACTERSET US7ASCII
FIELDS TERMINATED BY WHITESPACE
MISSING FIELD VALUES ARE NULL
(acr CHAR( 4),
name CHAR(20) TERMINATED BY '/n'))
LOCATION ('NFL_Teams.dat'))
REJECT LIMIT UNLIMITED
NOPARALLEL
/
SELECT * FROM nflteams_ext
2 /
ACR NAME
NO New Orleans Saints
PIT Pittsburgh Steelers
IND Indianapolis Colts
3 rows selected.

Related

Oracle External Table - No Rows Selected

I've created an external table using the following definition
CREATE TABLE EXT_TABLE (CID NUMBER, CNAME VARCHAR2(20), FEES NUMBER)
ORGANIZATION EXTERNAL
(
TYPE ORACLE_LOADER
DEFAULT DIRECTORY TEST_DIR
ACCESS PARAMETERS
(RECORDS DELIMITED BY NEWLINE
FIELDS TERMINATED BY ','
(
CID INTEGER,
CNAME CHAR(20),
FEES INTEGER
)
)
LOCATION ('DATA.TXT'))
REJECT LIMIT UNLIMITED;
table has been created. But, when i try to select data from table, I don't find any records
SQL> select * from ext_table;
no rows selected
I've made sure directory and table have sufficient privileges for the user.
The data in text file;
1,JAVA,300
2,LINUX,400
3,ORACLE,400
4,EXCEL,500
RECORD is not the keyword you should use here.
it must be RECORDS.
Use this:
RECORDS DELIMITED BY NEWLINE
Cheers!!

Oracle loader skip lines

In a CSV, using oracle loader, how can I skip lines that aren't the header?
For exemple:
Names;Initials
SomethingForSkip
Name1;Inital1
Name2;Inital2
SomethingForSkip
Name3;Inital3
Name4;Inital4
At the moment I have this code:
CREATE TABLE t_ext_course(
UC CHAR(100),
SCIENTIFIC_FIELD CHAR(10),
DEPARTAMENT CHAR(100)
)
ORGANIZATION EXTERNAL
(
TYPE oracle_loader
DEFAULT DIRECTORY src_files
ACCESS PARAMETERS
(
RECORDS DELIMITED BY newline
BADFILE 'course.bad'
DISCARDFILE 'course.dis'
LOGFILE 'course.log'
SKIP 3
FIELDS TERMINATED BY ";" OPTIONALLY ENCLOSED BY '"' MISSING FIELD VALUES ARE NULL
(
UC CHAR(100),
SCIENTIFIC_FIELD CHAR(10),
DEPARTAMENT CHAR(100)
)
)
LOCATION ('course.csv')
)
REJECT LIMIT UNLIMITED;
Thank you in advance for your help.
You can use the LOAD WHEN parameter. You would put it in right after your SKIP 3 parameter.
With LOAD WHEN, you can specify conditions so that only the source file rows meeting that condition will be loaded.
SQL*Loader and, by extension, external tables of type oracle_loader offer a BLANKS keyword that you can use to check for empty fields. It is useful for delimited data where you do not know the field length.
You can put it all together like this:
LOAD WHEN (SCIENTIFIC_FIELD != BLANKS)

Unable to load data using external table

I'm trying to load data in an external table from a csv file.
Following is my fragment:
create table emp_ext
(
eid number,ename char(9)
)
organization external
(
TYPE ORACLE_LOADER
DEFAULT DIRECTORY test
ACCESS PARAMETERS
(
RECORDS DELIMITED BY NEWLINE
FIELDS TERMINATED BY ','
(
eid number,
ename char(9)
)
)
LOCATION('C:\Users\99002971\Desktop\empf.csv')
)
create directory test as 'C:\Users\99002971\Desktop'
grant read on directory test to matuat35 // granted using another user
When i do select * from emp_ext , i get following errors:
ORA-29913:Error in executing ODCIEXTTABLEOPEN callout
ORA-29400:data cartridge error
KUP-00554:error encountered while parsing access parameters
KUP-01005:syntax error:found ""identifier:expecting one of :"binary_float,binary_double,comma,char,date,double"
KUP-01008:the bad identifier was double
KUP-01007:at line 4 column 12
Please help
The datatype_spec section of the external table documenation shows that number isn't recognised by the loader driver. In your code that is being seen as an identifier rather than a data type, hence the error.
You can use oracle_number, or unsigned integer since it's presumably always going to be a positive integer for an employee ID; or leave it untyped and allow implicit conversion to the table column type.
Your location should also only specify the file name within the directory, not the full path:
create table emp_ext
(
eid number,ename varchar2(15)
)
organization external
(
TYPE ORACLE_LOADER
DEFAULT DIRECTORY test
ACCESS PARAMETERS
(
RECORDS DELIMITED BY NEWLINE
FIELDS TERMINATED BY ','
(
eid unsigned integer external(9),
ename char(15)
)
)
LOCATION('empf.csv')
)
Or more simply, but relying on implicit conversion:
...
ACCESS PARAMETERS
(
RECORDS DELIMITED BY NEWLINE
FIELDS TERMINATED BY ','
(
eid,
ename char(15) rteim
)
)
LOCATION('empf.csv')
)

Oracle external tables

I'm struggling with an Oracle external table, although I researched the Oracle forums. Still, no success.
Let's suppose I have a simple table
DESCRIBE PRODUCTS
Name Null Type
------------------------------ -------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ID NOT NULL NUMBER
NAME VARCHAR2(30)
VALUE NUMBER(5,2)
DEP VARCHAR2(30)
COUNT NUMBER(3)
Then, I created an oracle folder:
CREATE OR REPLACE DIRECTORY ext_prod_dir AS 'c:\';
I save the content of that table in a .lst file
spool c:\products.lst
select p.id || ';' || p.name || ';' || p.value || ';' || p.dep || ';' || p.count FROM products p;
spool off;
P.ID||';'||P.NAME||';'||P.VALUE||';'||P.DEP||';'||P.COUNT
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1;Settlers of Catan;29,95;Toys;3
2;DVD Player;82,97;Electronics;2
3;Red Shirt;12,49;Clothes;3
4;Black Leather Couch;399,99;Furniture;5
5;Oak Cofee Table;223,99;Furniture;5
6;Technodrome;27,99;Toys;4
7;Oh Cereal;3,95;Foods;1
8;Game Console;299,95;Toys;2
9;Video Game;29,95;Toys;3
10;Lawn Chair;34,99;Furniture;11
11;Dog Toy Bone;34,99;Toys;9
12;Heated Blanket;27,95;Toys;8
13;Flux Capacitor;27,95;Toys;7
14;Chocolate Pie;3,14;Foods;7
Then I tried to create the external table:
CREATE TABLE products_ext
(ID NUMBER,
NAME VARCHAR2(30),
VALUE NUMBER(5,2),
DEP VARCHAR2(30),
COUNT NUMBER(3))
ORGANIZATION EXTERNAL
(TYPE oracle_loader DEFAULT DIRECTORY ext_prod_dir
ACCESS PARAMETERS
(RECORDS DELIMITED BY NEWLINE
FIELDS TERMINATED BY ';'
MISSING FIELD VALUES ARE NULL
BADFILE ext_prod_dir:'products.bad_xt'
LOGFILE ext_prod_dir:'products.log_xt'
(ID CHAR(6),
NAME CHAR(30),
VALUE CHAR(8),
DEP CHAR(30),
COUNT CHAR(3)))
location ('products.lst')
) REJECT LIMIT UNLIMITED
So far so good. Then when I select data from the external table, I got:
ORA-29913: error in executing ODCIEXTTABLEOPEN callout
ORA-29400: data cartridge error
KUP-00554: error encontered while parsing access parameters
KUP-01005: syntax error: found "badfile": expecting one of: "column (,reject"
KUP-01007: at line 4 column 7
I tried a huge amount of things, but I got variations on this error. Best thing I accomplished was that I got rid of error, but the table was empty. I would be very much indebted If someone with more experience can point me in the right direction.
BADFILE and LOGFILE are not part of the FIELDS clause. So, move them above the FIELDS TERMINATED.
CREATE TABLE products_ext
(ID NUMBER,
NAME VARCHAR2(30),
VALUE NUMBER(5,2),
DEP VARCHAR2(30),
COUNT NUMBER(3))
ORGANIZATION EXTERNAL
(TYPE oracle_loader DEFAULT DIRECTORY ext_prod_dir
ACCESS PARAMETERS
(RECORDS DELIMITED BY NEWLINE
BADFILE ext_prod_dir:'products.bad_xt'
LOGFILE ext_prod_dir:'products.log_xt'
FIELDS TERMINATED BY ';'
MISSING FIELD VALUES ARE NULL
(ID CHAR(6),
NAME CHAR(30),
VALUE CHAR(8),
DEP CHAR(30),
COUNT CHAR(3)))
LOCATION ('products.lst')
) REJECT LIMIT UNLIMITED
Also, you said when you got rid of the error, the table was empty. Did you check the logfile? If the error is with the VALUE column, then check NLS_NUMERIC_CHARACTERS parameter
in view v$nls_parameters.
select * from v$nls_parameters;
Check if the decimal marker is indeed a comma. If not either update this parameter or change it in the data file.

Oracle 10G external table error

I have created the following external table on Oracle 10G.
connect system/password as SYSDBA
create or replace directory ext_tab as 'C:\Suman\External_Tables';
CREATE TABLE emp_ext_3(
empno NUMBER(4), first_name CHAR(20), last_name CHAR(20), dob CHAR(10))
ORGANIZATION EXTERNAL(
TYPE ORACLE_LOADER DEFAULT DIRECTORY ext_tab
ACCESS PARAMETERS
(
RECORDS DELIMITED BY NEWLINE
NOBADFILE
NOLOGFILE
SKIP 1
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LRTRIM
MISSING FIELD VALUES ARE NULL
REJECT ROWS WITH ALL NULL FIELDS
(empno INTEGER EXTERNAL (4),
first_name CHAR(20),
last_name CHAR(20),
dob CHAR(10) DATE_FORMAT DATE MASK "dd/mm/yyyy")
)
LOCATION ('employee1.dat')
)
PARALLEL
REJECT LIMIT 0;
Now If I try to execute select command, I am getting following error.
SQL> select * from "SYSTEM"."EMP_EXT_3";
select * from "SYSTEM"."EMP_EXT_3"
*
ERROR at line 1:
ORA-29913: error in executing ODCIEXTTABLEOPEN callout
ORA-29400: data cartridge error
KUP-04040: file employee1.dat in EXT_TAB not found
ORA-06512: at "SYS.ORACLE_LOADER", line 19
But I have the file "employee1.dat" in 'C:\Suman\External_Tables'. Can someone please help me on why I am getting this error?
The Oracle server is looking for a file in the following location: 'C:\Suman\External_Tables'. That directory is on the Oracle server machine, not your local Windows client machine.

Resources