Error while loading file in Oracle - sql

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;

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.

Invalid table name while bulk insert in oracle

I am trying to insert values into Oracle table using Bulk Insert query but getting below error
ORA-00903: invalid table name
00903. 00000 - "invalid table name"
*Cause:
*Action:
Error at Line: 4 Column: 5
Here is my query
BULK INSERT TEST1.STUDENT
FROM 'C:\Users\Alan\Desktop\STUDENT.txt'
WITH
(
FIELDTERMINATOR = '\t',
ROWTERMINATOR = '\n'
);
Why is this error coming. Is there some issue with query? Please help. Thanks
Update
I changed by file format to CSV and wrote below query
LOAD DATA
INFILE 'C:\Users\Alan\Desktop\STUDENT.csv'
INTO TABLE TEST1.STUDENT
FIELDS TERMINATED BY ","
(ID,
NAME);
but above query is giving
ORA-00928: missing SELECT keyword
00928. 00000 - "missing SELECT keyword"
*Cause:
*Action:
Error at Line: 16 Column: 2
What is wrong in the above syntax?
This is not Oracle syntax at all. If you need to load data from file to table please use either SQLoader or External table
Some documentation about External table and SQLoader
If you're using SQLDeveloper you can also use import facility.
Please also have a look on that thread.
[EDIT}
LOAD DATA
INFILE 'C:\Users\Alan\Desktop\STUDENT.csv'
INTO TABLE TEST1.STUDENT
FIELDS TERMINATED BY ","
(ID,
NAME);
This is not a query. This is content of control file. Please save it to file load.csv then run cmd (or shell if yuo're on Linux) and type:
sqlldr user/pass control=load.ctl
Some examples you can find here.

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

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

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 .

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.