sqlloader syntax error on command line - oracle

I can't figure out where is the syntax error in this case trying to execute the sqlloader by command line. It seems to be ok.
Command:
sqlldr myuser/mypass#myhost:1521/orcl CONTROL=tbx.ctl LOG=C:\path\to\tbx.log BAD=C:\path\to\tbx.bad skip=0
CTL file:
load data
infile 'C:\path\to\tbx.csv'
into table TBX
fields terminated by ';'
optionally enclosed by '"' AND '"'
( x,
xx,
xxx,
xxxx,
xxxxx,
xxxxxx,
xxxxxxx,
xxxxxxxx,
xxxxxxxxx
)
CSV file:
"724098100357859";"";"";"";"";"";"";""
"724098100358417";"";"";"";"";"";"";""
...
ERROR:
SQL*Loader-100: Syntax error on command-line
Table structure:
CREATE TABLE TBX
(
"x" VARCHAR2(20 BYTE),
"xx" VARCHAR2(80 BYTE),
"xxx" VARCHAR2(80 BYTE),
"xxxx" VARCHAR2(80 BYTE),
"xxxxx" VARCHAR2(60 BYTE),
"xxxxxx" VARCHAR2(60 BYTE),
"xxxxxxx" VARCHAR2(60 BYTE),
"xxxxxxxx" VARCHAR2(60 BYTE),
"xxxxxxxxx" VARCHAR2(80 BYTE)
)

If your paths have spaces in them then SQL*Loader will see a path as more than one argument, usually generating an LRM-00112 error. You haven't shown that but from comments that does seem to be the issue. You need to enclose the paths in quotes:
sqlldr myuser/mypass#myhost:1521/orcl CONTROL='tbx.ctl' LOG='C:\path\with spaces\tbx.log' BAD='C:\path\with spaces\tbx.bad' skip=0
Off-topic from the original question, but picking up from a comment... When you use #myhost:1521/orcl as your connect string, you're using an easy connection identifier (link is for SQL*Plus, but the same applies here). The final element of that is the service name for the database, which may not be the same as the SID - it could be orcl.example.com, for instance. On the database server you can run lsnrctl status or lsnrctl services to see what service names are valid. If you already have a working tnsnames.ora, though, you can use the TNS alias instead, e.g. sqlldr myusr/mypass#orcl.

Related

Odie's EXCELTABLE.GETROWS() returns ORA-20731: Error at position 632243, expecting a [String] record

I have a requirement where I have to read the compressed zip blob of XLS files in the Oracle database 19c, and process the sheets inside each XLS file, using PLSQL.
I am using APEX_ZIP package and Odie's EXCELTABLE for this.
I am able to do it by first getting the individual Excel file BLOBs using apex_zip package
and passing the BLOB to EXCELTable.GetRowsto read the Excel sheets in the BLOB.
It works fine for few Excel sheets but for a few it gives me this error:
ORA-20731: Error at position 632243, expecting a [String] record
The sheets are all Character data.
This is a snippet of the code I use:
SELECT t.*
FROM Table(
ExcelTable.getRows(
(select fileblob from md_blob where lower(filename) like '%renew%')
,ExcelTableSheetList('Ownership - RENEW')
,' "COL1" varchar2(200 char)
, "COL2" varchar2(200 char)
, "COL3" varchar2(200 char)
, "COL4" varchar2(200 char)
, "COL5" varchar2(200 char)
, "COL6" varchar2(200 char)
, "COL7" varchar2(200 char)
, "COL8" varchar2(200 char)'
, '9:10'
)
)
;
Any thoughts on how to deal with it?
There is data in the spreadsheet.
If you are able to get the files as XLSX, not XLS, you can use the APEX_DATA_PARSER package to query the Excel file as if it was a table. This makes it much easier as you will not need to write any code of your own to unzip the files and dig through the contents.

Oracle database 11: select * from table fails

I have a weird issue. In one of the production DB servers we are trying to run
select * from SCHEMA_NAME.TABLE_NAME
When we run the query we are getting invalid identifier error. But when we select a particular column and run the same select query on the same table , we are able to get the output.
Please help me to understand the root cause.
Type created:
create or replace
TYPE "TEST_TYPE" is object
(
MULTIROW_ID VARCHAR2(100 CHAR),
LOSS_ENTRY_TYPE VARCHAR2(1000 CHAR),
SUB_CATEGORY VARCHAR2(1000 CHAR),
LOSS_AMOUNT NUMBER,
LOSS_ENTRY_CURR VARCHAR2(100 CHAR)
);
Type 2 created:
create or replace
TYPE "TEST_TYPE1" AS TABLE OF TEST_TYPE;
Main create table query using above table type columns:
CREATE TABLE "MS_TEST_DATA"
( "REGION" VARCHAR2(4000 CHAR),
"Entries" "TEST_TYPE1" ,
"ILE_DET_FUNCTION_OF_DISC_COM" VARCHAR2(4000 CHAR)
)
NESTED TABLE "Entries" STORE AS "TEST_TYPE3";
If I run this locally, I am able to access the table with select * query.
but in server I don't have all the accesses. There I have read-only access to tables. I can only run select * queries.
Avoid using double quotes in DDL scripts. If it is system generated, write a script to eliminate double quotes wherever possible.

Oracle 11g _ ORA-00904 error message with Insert statement

I created a simple table:
CREATE TABLE "ADVUPGRD"."GL_CAMPUSEMAILS"
("Campus" VARCHAR2(2 CHAR), "SEND_TO" VARCHAR2(60 CHAR), "SEND_CC"
VARCHAR2(250 CHAR), "SEND_BCC" VARCHAR2(60 CHAR))
The table got created, I can do select * from gl_campusemails and it gets me a blank row since I have not populated this table yet.
When I'm populating the table I'm using this:
INSERT INTO GL_CAMPUSEMAILS (Campus, Send_To, Send_CC, Send_BCC)
VALUES('CP', 'as#gmail.com', 'test#yahoo.com', 'test2#gmail.com');
but I got this error message:
Error starting at line : 8 in command -
INSERT INTO GL_CAMPUSEMAILS (Campus, Send_To, Send_CC, Send_BCC)
VALUES('CP', 'as#gmail.com', 'test#yahoo.com', 'test2#gmail.com')
Error at Command Line : 8 Column : 56
Error report -
SQL Error: ORA-00904: "SEND_BCC": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
I googled and found a lot of posting but they're mostly related to the use of reserved words in the select statement.
I don't think the columns I used in here belong to any reserved words.What did I do wrong in here
If you use double quotes while creating the table, the column names are created exactly as you typed, case sensitive; thus, you insert should be:
INSERT INTO GL_CAMPUSEMAILS(
"Campus",
"SEND_TO",
"SEND_CC",
"SEND_BCC"
)
VALUES (
'CP',
'as#gmail.com',
'test#yahoo.com',
'test2#gmail.com'
);
If you create the table with no quotes, this will work fine
CREATE TABLE GL_CAMPUSEMAILS
(
Campus VARCHAR2(2 CHAR),
SEND_TO VARCHAR2(60 CHAR),
SEND_CC VARCHAR2(250 CHAR),
SEND_BCC VARCHAR2(60 CHAR)
);
INSERT INTO GL_CAMPUSEMAILS(
Campus,
SEND_TO,
SEND_CC,
SEND_BCC
)
VALUES (
'CP',
'as#gmail.com',
'test#yahoo.com',
'test2#gmail.com'
);
Notice that not using double quotes, Oracle will consider all the objects with upper case names; so, for example, "CAMPUS", campus, CaMpUs will work, while "campus" will not

sql*loader loading csv file with 3.5 million records

How can i load csv file with 3.5 million records into database table?
my csv file format:
code,doi,type,j_code,title,is_no,ib_no
"ETO072","10.10ISSN","J_ID","BEJ","ABCDEF","19-38","07-93"
"ETO073","10.11ISSN","J_ID","BEJ","NSKDJJ","19-39","07-94"
"ETO074","10.12ISSN","J_ID","BEJ","WEWDSD","19-40","07-95"
"ETO075","10.13ISSN","J_ID","BEJ","UOISDJ","19-41","07-96"
table structure:
CREATE TABLE CNTNT
( ID NUMBER,
code NUMBER,
TYPE VARCHAR2(255 BYTE),
is_no VARCHAR2(13 BYTE),
ib_no VARCHAR2(13 BYTE),
J_code VARCHAR2(255 BYTE),
TITLE VARCHAR2(1000 BYTE),
JCODE VARCHAR2(20 BYTE),
DOI VARCHAR2(255 BYTE),
PRIMARY KEY (ID),
);
control file:
load data
infile 'test.csv' "str '\n'"
append
into table CNTNT
fields terminated by ','
OPTIONALLY ENCLOSED BY '"' AND '"'
trailing nullcols
(
code,
DOI ,
TYPE,
J_CODE ,
TITLE ,
is_no,
ib_no,
ID "id_seq.nextval"
)
this is what i am using to run loader:
sqlldr CONTROL=test.ctl
LOG=test.log
BAD=test.bad
skip=1;
What are the changes i need to do in control file or sqlldr command to achieve this?

Oracle External Table - How to convert field to a date?

I'm loading some data into oracle using an external table. One of the fields "CREATEDON" is a date but is formatted like this 20151231
How can I convert CREATEDON to a proper oracle date datatype. This is my attempt so far which doesn't work...
CREATE TABLE "AMS"."DATA"
( "BLANK" VARCHAR2(255 BYTE),
"BLANK2" VARCHAR2(255 BYTE),
"CLIENT" VARCHAR2(255 BYTE),
"MATERIAL" DATE,
"CREATEDON" VARCHAR2(255 BYTE)
)
ORGANIZATION EXTERNAL
( TYPE ORACLE_LOADER
DEFAULT DIRECTORY "DIR"
ACCESS PARAMETERS
( records delimited BY '\r\n'
skip 1
fields terminated BY '|' lrtrim missing field VALUES are NULL
)
LOCATION ( "DIR":'foo.txt' )
)
REJECT LIMIT UNLIMITED ;
You have two options:
Keep as is, and transform in your select statements, such as:
select ..., to_date(CREATEDON,'YYYYMMDD') CREATEDON
Define the format in the table DDL:
"CREATEDON" VARCHAR2(255 BYTE) DATE_FORMAT DATE MASK "YYYYMMDD"

Resources