Oracle loader - error defining access parameters (KUP-01005) - sql

I'm having problem querying the following table loaded from a file.
CREATE TABLE "testTable"
(
"EAN" NUMBER(38,0),
"STOCK" NUMBER(38,0),
"SECCION" NUMBER(38,0)
)
organization external
( default directory xtern_data_dir
access parameters
( fields terminated by ';'
badfile xtern_data_dir:'testTable.bad'
logfile xtern_data_dir:'testTable.log'
discardfile xtern_data_dir:'testTable.dsc'
)
location ('0025_STOCK.csv')
)
But I'm getting the following error:
KUP-01005: syntax error: found "badfile": expecting one of: "column, enclosed, (, ltrim, lrtrim, ldrtrim, missing, notrim, optionally, rtrim, reject"
I have tried removing badfile, logfile and discardfile, but then I get another error, and I'm not sure how to make it work.
Please, help! Thanks in advance.

Try to use
CREATE TABLE "testTable"
(
"EAN" NUMBER(38,0),
"STOCK" NUMBER(38,0),
"SECCION" NUMBER(38,0)
)
organization external
( default directory xtern_data_dir
access parameters
( RECORDS DELIMITED BY newline
badfile xtern_data_dir:'testTable.bad'
logfile xtern_data_dir:'testTable.log'
discardfile xtern_data_dir:'testTable.dsc'
fields terminated by ';'
)
location ('0025_STOCK.csv')
)

Related

ORA-29913: error in executing ODCIEXTTABLEOPEN callout

I am creating external table using hr schema but i get 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 "missing": expecting one of:
"column, (" KUP-01007: at line 4 column 3
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."
----------------My Code-------------------
create directory ex_tab as 'C:\My Works\External Table';
create table strecords (
st_id number(4),
st_name varchar(10),
schl_name varchar(5),
st_city varchar(15),
st_year number(4)
)
ORGANIZATION EXTERNAL
(TYPE oracle_loader
DEFAULT DIRECTORY ex_tab
ACCESS PARAMETERS
(
RECORDS DELIMITED BY newline
FIELDS TERMINATED BY ','
REJECT ROWS WITH ALL NULL FIELDS
MISSING FIELDS VALUES ARE NULL
(
st_id number(4),
st_name char(10),
schl_name char(5),
st_city char(15),
st_year number(4)
)
)
LOCATION ('strecords.txt')
);
desc strecords;
select * from strecords;
This is my code, please check it and review it.
You have several issues here. The immediate one causing your problem is that you have the clauses in the wrong order, but you also have MISSING FIELDS instead of MISSING FIELD:
...
ACCESS PARAMETERS
(
RECORDS DELIMITED BY newline
FIELDS TERMINATED BY ','
MISSING FIELD VALUES ARE NULL
REJECT ROWS WITH ALL NULL FIELDS
(
...
Then your field list contents have invalid data types for that part of the statement; you can just omit that entirely in this case as those match the table column definition.
If no field list is specified, then the fields in the data file are assumed to be in the same order as the fields in the external table.
So you can simplify it to:
create table strecords (
st_id number(4),
st_name varchar(10),
schl_name varchar(5),
st_city varchar(15),
st_year number(4)
)
ORGANIZATION EXTERNAL
(TYPE oracle_loader
DEFAULT DIRECTORY ex_tab
ACCESS PARAMETERS
(
RECORDS DELIMITED BY newline
FIELDS TERMINATED BY ','
MISSING FIELD VALUES ARE NULL
REJECT ROWS WITH ALL NULL FIELDS
)
LOCATION ('strecords.txt')
);
Some operations needed against an Oracle Bug called
Select From External Table Returns Errors ORA-29913 ORA-29400 KUP-554 KUP-1005 (Doc ID 302672.1)
When creating an external table, the access parameters should be specified in the following order:
Comments
Record Format Info
Field definitions
Specify Comments, Record Format Info and Field definitions in the correct order. Even inside the Record format Info, 'Records delimited by ...' clause should come before any other clause.
For more information, refer to the access_parameters clause.

How to read a field Oracle containing XML

A table exists in the environment of production with the following structure:
CREATE TABLE gold_dwh_reload (
msisdn NUMBER(13,0) NOT NULL,
recharge_date TIMESTAMP(6) NOT NULL,
impacted_balances VARCHAR2(4000) NULL,
lc_state VARCHAR2(5) NOT NULL)
TABLESPACE sopfun_tab
NOCOMPRESS
/
A normal consultation would the following result by example:
MSISDN RECHARGE_DATE IMPACTED_BALANCES LC_STATE
584124723950 29.04.15 13:23:38.000 <balance><name>B_LPP_Bs_Main</name><label></label><before>697.21429</before><after>797.21429</after><amount>100</amount><start></start><end></end><unit>Bs</unit></balance><balance><name>B_LPP_KB_National</name><label>PA_Adjustment</label><before>0</before><after>10240</after><amount>10240</amount><start>29042015000000</start><end>29052015000000</end><unit>Kbytes</unit></balance><balance><name>B_LSP_Bs_Promotions</name><label>PA_Adjustment</label><before>0</before><after>25</after><amount>25</amount><start>29042015000000</start><end>29052015000000</end><unit>Bs</unit></balance> ACT
But i need to break the IMPACTED_BALANCES field in columns. Anyone know how I do it?
This is typically done using XMLTable
select
msisdn, recharge_date,
x_name, x_label, x_before, x_after, x_amount,
to_date(x_start, 'DDMMYYYYHH24MISS') x_start,
to_date(x_end, 'DDMMYYYYHH24MISS') x_end,
x_unit,
lc_state
from gold_dwh_reload
cross join
xmltable('/balances/balance'
passing xmltype('<balances>'||impacted_balances||'</balances>')
columns
x_name path '/balance/name',
x_label path '/balance/label',
x_before number path '/balance/before',
x_after number path '/balance/after',
x_amount number path '/balance/amount',
x_start path '/balance/start',
x_end path '/balance/end',
x_unit path '/balance/unit'
);
Here's a SQL Fiddle.
Mixing SQL and XML is powerful but creates many potential type safety issues. A single invalid date, number, or XML file will crash the whole query. The string in your example is not valid XML, that's why I concatenated another tag to the beginning and end.

example of an external table which accepts all records from a file

Please can any one tell me how to accept all records from a file so that no record should go to discard or bad file using external table concept.
Below is the code
CREATE TABLE ext_tab2 (
mprn CHAR(10))
ORGANIZATION EXTERNAL (
TYPE ORACLE_LOADER
DEFAULT DIRECTORY IMPORT
ACCESS PARAMETERS (
RECORDS DELIMITED BY NEWLINE
BADFILE IMPORT:'test.bad'
LOGFILE IMPORT:'test.log'
FIELDS TERMINATED BY ','
(mprn char(10)))
LOCATION ('abc.txt')
)
PARALLEL 5
REJECT LIMIT UNLIMITED;
All the data from file('abc.txt') should get inserted into ext_tab2 table .

Error while loading file in Oracle

I have been trying to load a text file in oracle database using SQL loader.
Please find my query below:-
CREATE TABLE test_test
(
numb int
)
ORGANIZATION EXTERNAL
(
TYPE ORACLE_LOADER
DEFAULT DIRECTORY dir_test
ACCESS PARAMETERS
(
RECORDS DELIMITED BY NEWLINE
BADFILE 'testscript.bad'
DISCARDFILE 'testscript.dis'
LOGFILE 'testscript.log'
SKIP 0
(
numb int
)
)
LOCATION (dir_test:'test.txt')
)
REJECT LIMIT 0
PARALLEL (DEGREE DEFAULT INSTANCES DEFAULT)
NOMONITORING;
However I am getting the following errors when I try select * from test_test:
ERROR at line 1:
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 "(": expecting one of: "badfile, byteordermark,
characterset, data, delimited, discardfile, exit, fields, fixed, load, logfile,
nodiscardfile, nobadfile, nologfile, date_cache, processing, readsize, string,
skip, variable"
KUP-01007: at line 6 column 10
ORA-06512: at "SYS.ORACLE_LOADER", line 14
ORA-06512: at line 1
Please suggest wjhat is the probable reason for this ? I am trying to run this on sqlplus on unix environment. dir_test is the oracle directory which i created earlier
You are missing the keyword fields before (numb int) and int is not valid here.
CREATE TABLE test_test (numb int)
ORGANIZATION EXTERNAL (
TYPE ORACLE_LOADER
DEFAULT DIRECTORY dir_test
ACCESS PARAMETERS (
RECORDS DELIMITED BY NEWLINE
BADFILE 'testscript.bad'
DISCARDFILE 'testscript.dis'
LOGFILE 'testscript.log'
SKIP 0
FIELDS (numb integer))
LOCATION (dir_test:'test.txt'))
REJECT LIMIT 0
PARALLEL (DEGREE DEFAULT INSTANCES DEFAULT)
NOMONITORING;

External table creation in oracle using csv from ftp location

I am trying to load the csv file data into external_tables for this i have tried
create table ext_table_csv (
i Number,
n Varchar2(20),
m Varchar2(20)
)
organization external (
type oracle_loader
default directory ext_dir
access parameters (
records delimited by newline
fields terminated by ','
missing field values are null
)
location ('f
ile.csv')
)
reject limit unlimited;
but i got error as
Error starting at line 8 in command:
create table ext_table_csv (
i Number,
n Varchar2(20),
m Varchar2(20)
)
organization external (
type oracle_loader
default directory ext_dir
access parameters (
records delimited by newline
fields terminated by ','
missing field values are null
)
location ('f
ile.csv')
)
reject limit unlimited
Error at Command Line:15 Column:23
Error report:
SQL Error: ORA-06564: object DATA_DIR does not exist
06564. 00000 - "object %s does not exist"
*Cause: The named object could not be found. Either it does not exist
or you do not have permission to access it.
*Action: Create the object or get permission to access it.
what i have to do is i want to read the csv file from ftp location. Is there any way to acheive this?
You probably need to specify the location of the file.
location (FTP_DIRECTORY:'emp.dat')
Where FTP_DIRECTORY is an Oracle Directory object pointing to the location where you placed
the file.