I'm trying to create External table but I got stuck - oracle

I'm able to create table successfully but whenever I'm fetching external table I got error
create table xyz ( t1 varchar2(20),t2 varchar(10),t3 varchar(10),t4 date,t5 varchar(10),t6 varchar(10),t7 varchar(10),t8 varchar(20),t9 varchar(25),t10 varchar(60),t11 varchar(60))
ORGANIZATION EXTERNAL (
TYPE ORACLE_LOADER
DEFAULT DIRECTORY DE_DUBFILE
ACCESS PARAMETERS
(
RECORDS DELIMITED BY NEWLINE
BADFILE DE_DUBFILE: 'xyz.bad'
DISCARDFILE DE_DUBFILE: 'xyz.dis'
LOGFILE DE_DUBFILE: 'xyz.log'
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
MISSING FIELD VALUES ARE NULL
(
t1,t2,t3,t4 date "YYYYMMDD",t5,t6,t7,t8,t9,
t10 "ORA_HASH(:t1||:t2||:t3 )",
t11 "ORA_HASH(:t6||:t8||:t9 )"
)
)
LOCATION (DE_DUBFILE:'ZZZ'));
I'm getting below error
ORA-29400: data cartridge error
KUP-00554: error encountered while parsing access parameters
KUP-01005: syntax error: found "double-quoted-string": expecting one of: "binary_double, binary_float, comma, char, date, defaultif, decimal, double, float, integer, (, no, nullif, oracle_date, oracle_number, position, raw, recnum, ), unsigned, varrawc, varchar, varraw, varcharc, zoned"
KUP-01007: at line 11 column 57
Script Terminated on line 26.

It seems to me that "ORA_HASH(:t1||:t2||:t3 )" can't be processed.
Try to load without them (t10 and t11) and generate these fields after all.

Related

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')
)

error while trying to select from external table

I am getting the below error while trying to select * from ext_poc
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_double, binary_float, comma, char, date, defaultif, decimal, double, float, integer, (, no, nullif, oracle_date, oracle_number, position, raw, recnum, ), unsigned, varrawc, varchar, varraw, varcharc, zoned"
KUP-01008: the bad identifier was: varchar2
KUP-01007: at line 4 column 10
29913. 00000 - "error in executing %s callout"
*Cause: The execution of the specified callout caused an error.
*Action: Examine the error messages take appropriate action.
Below is the ddl for the table:
CREATE TABLE "JDASTG"."EXT_POC"
( "ID" varchar2(100),
"NAME" varchar2(100),
"DOB" varchar2(100)
)
ORGANIZATION EXTERNAL
( TYPE ORACLE_LOADER
DEFAULT DIRECTORY "SCPO_EXT_DATA"
ACCESS PARAMETERS
( RECORDS DELIMITED BY NEWLINE
FIELDS TERMINATED BY ','
MISSING FIELD VALUES ARE NULL
(id varchar2(100),
name varchar2(100),
dob varchar2(100)
)
)
LOCATION
( 'xyz_aldrin.csv'
)
);
PS:
This error however doesn't occur if the varchar2(100) is changed to char(100):
MISSING FIELD VALUES ARE NULL
(id char(100),
name char(100),
dob char(100)
)
It is important to distinguish between oracle internal data types specified on the table, and the external data types specified in the access parameters for the external table (control file for sqlldr). Read the manual again with that in mind. It should become clear. CHAR is allowed in SQL loader whereas VARCHAR2 is not

Loading data in external table SQLLoader

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.

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.

Resources