Expressions in SQL*Loader
All SQLs in this construction fail:
column_name EXPRESSION "SQL string"
What's wrong? And what SQLs are allowed in this case?
Hi
To my knowledge, this can't be achieved with SQL*Loader concurrent programs. Depending on what You are using the request id, the options provided may be useful.
I had a similar issue, requiring the use of user_id and login_id for who columns, and the solution applied was:
- Define a template for the control file, with place holders for the additional info:
user_id constant "x_user_id"
- Create a shell to receive the additional info as parameters, and use sed to change the template file to generate the control file, using the parameter to replace placeholders.
Create a request set to launch the shell concurrent program and then the sql loader program, whose control file now has the additional information required.
Caution when more than one middle tier node is used.
Similar Messages
-
ORA-00936 error from SQL expression in SQL*Loader script
I am getting the above error on the following line in my SQL*Loader script:
DIA_CLM_RES_OID DECIMAL EXTERNAL
"SELECT N_ORG_ENTY_ID FROM TESTG4.ORG_ENTITY
WHERE N_USER_ID =
(SELECT UNIQUE WSR_NT_ID FROM CONV_CLM_RESOURCE
WHERE CLM_RES_OID = :DIA_CLM_RES_OID)",
What I am basically trying to do is a 2-table lookup of a value:
1. Find a row in table CONV_CLM_RESOURCE where the value in column CLM_RES_OID matches the value in the input file in field DIA_CLM_RES_OID.
2. Take the value of field WSR_NT_ID from that row and use it to find a row in table TESTG4.ORG_ENTITY.
3. Take the value of field WSR_NT_ID from that row and set it in the target table in field DIA_CLM_RES_OID.
In other words, I am essentially trying to translate the input value by using two other tables to lookup the value to translate to. However, no matter how I arrange it, I keep getting the "ORA-00936: missing expression" error on this statement.
Can anyone see what I am doing wrong, or perhaps suggest a better way of accomplishing a two-table translation of a value?
Thanks!Still not sure why this doesn't work, but I was able to create and use a function to do this instead, which is probably a better approach anyway.
-
Error while using expressions with direct path sql loader
We are using an expression (substr) in the control file while loading the data into a table T using sql loader using a user U.
The user U does not have permissions to the table T directly but through a role R.
While running the sql loader using direct=true option (because the data load is very huge), an error 'table or view does not exist' is thrown.
This error does not occur when conventional path is used; or when the user is given permissions on the table directly. We dont want to use both these options. Is there any other solution to this problem?
Thanks!We are using an expression (substr) in the control file while loading the data into a table T using sql loader using a user U.
The user U does not have permissions to the table T directly but through a role R.
While running the sql loader using direct=true option (because the data load is very huge), an error 'table or view does not exist' is thrown.
This error does not occur when conventional path is used; or when the user is given permissions on the table directly. We dont want to use both these options. Is there any other solution to this problem?
Thanks! -
SQL*Loader and DECODE function
Hi All,
I am loading data from data files into oracle tables and while loading the data using SQL*Loader, the following requirement needs to be fulfilled.
1) If OQPR < 300, RB = $ 0-299, SC = "SC1"
2) If 300 < OQPR < 1200, RB = $ 300-1199, SC = "SC2"
3) If 1200 < OQPR < 3000, RB = $ 1200-2999, SC = "SC3"
4) If OQPR > 3000 USD, RB = > $3000, SC = "SC4"
Here OPQR is a field in the data file.
Can anyone suggest how do we handle this using DECODE function? Triggers and PL/SQL functions are not to be used.
TIA.
Regards,
Ravi.The following expression gives you different values for your different intervals and boundaries :
SIGN(:OQPR - 300) + SIGN(:OQPR - 1200) + SIGN(:OQPR - 3000) -
Hello all,
I am getting error while running below sql loader command...
load data
infile *
into TABLE AP_SUPPLIER_SITES_INT
REPLACE
fields terminated by ","
OPTIONALLY ENCLOSED BY '"'
VENDOR_INTERFACE_ID expression "to_char('select VENDOR_INTERFACE_ID from AP_SUPPLIERS_INT where CUSTOMER_NUM=:CUSTOMER_NUM')",
VENDOR_SITE_INTERFACE_ID "to_char(ap_supplier_sites_int_s.NEXTVAL)",
LAST_UPDATE_DATE "SYSDATE",
LAST_UPDATED_BY,
VENDOR_SITE_CODE,
CREATION_DATE "SYSDATE",
CREATED_BY,
PURCHASING_SITE_FLAG,
PAY_SITE_FLAG,
ADDRESS_LINE1,
ADDRESS_LINE2,
ADDRESS_LINE3,
CITY,
STATE,
ZIP,
COUNTRY,
PHONE,
FAX,
PAYMENT_METHOD_LOOKUP_CODE,
TERMS_ID,
CREATE_DEBIT_MEMO_FLAG,
HOLD_UNMATCHED_INVOICES_FLAG,
EMAIL_ADDRESS,
MATCH_OPTION,
EXCLUDE_FREIGHT_FROM_DISCOUNT,
INVOICE_CURRENCY_CODE,
PAYMENT_CURRENCY_CODE,
COUNTRY_OF_ORIGIN_CODE,
FREIGHT_TERMS_LOOKUP_CODE,
PAY_GROUP_LOOKUP_CODE,
PAY_DATE_BASIS_LOOKUP_CODE,
ALWAYS_TAKE_DISC_FLAG,
ORG_ID)
begindata
1005,,SYSDATE,1132,Test MA Site_1,SYSDATE,1132,Y,Y,No#907 62nd Street ,10th Sector,KK Nagar,Chennai,TamilNadu,600078,IN,+91 44 33333333,044 40404040,CHECK,10000,Y,N,[email protected],R,Y,INR,INR,IN,TBD,STANDARD,DISCOUNT,Y,120
Log file:
Table "AP"."AP_SUPPLIER_SITES_INT", loaded from every logical record.
Insert option in effect for this table: REPLACE
Column Name Position Len Term Encl Datatype
VENDOR_INTERFACE_ID EXPRESSION
SQL string for column : "to_char('select VENDOR_INTERFACE_ID from AP_SUPPLIERS_INT where CUSTOMER_NUM=:CUSTOMER_NUM')"
VENDOR_SITE_INTERFACE_ID FIRST * , O(") CHARACTER
SQL string for column : "to_char(ap_supplier_sites_int_s.NEXTVAL)"
LAST_UPDATE_DATE NEXT * , O(") CHARACTER
SQL string for column : "SYSDATE"
LAST_UPDATED_BY NEXT * , O(") CHARACTER
VENDOR_SITE_CODE NEXT * , O(") CHARACTER
CREATION_DATE NEXT * , O(") CHARACTER
SQL string for column : "SYSDATE"
CREATED_BY NEXT * , O(") CHARACTER
PURCHASING_SITE_FLAG NEXT * , O(") CHARACTER
PAY_SITE_FLAG NEXT * , O(") CHARACTER
ADDRESS_LINE1 NEXT * , O(") CHARACTER
ADDRESS_LINE2 NEXT * , O(") CHARACTER
ADDRESS_LINE3 NEXT * , O(") CHARACTER
CITY NEXT * , O(") CHARACTER
STATE NEXT * , O(") CHARACTER
ZIP NEXT * , O(") CHARACTER
COUNTRY NEXT * , O(") CHARACTER
PHONE NEXT * , O(") CHARACTER
FAX NEXT * , O(") CHARACTER
PAYMENT_METHOD_LOOKUP_CODE NEXT * , O(") CHARACTER
TERMS_ID NEXT * , O(") CHARACTER
CREATE_DEBIT_MEMO_FLAG NEXT * , O(") CHARACTER
HOLD_UNMATCHED_INVOICES_FLAG NEXT * , O(") CHARACTER
EMAIL_ADDRESS NEXT * , O(") CHARACTER
MATCH_OPTION NEXT * , O(") CHARACTER
EXCLUDE_FREIGHT_FROM_DISCOUNT NEXT * , O(") CHARACTER
INVOICE_CURRENCY_CODE NEXT * , O(") CHARACTER
PAYMENT_CURRENCY_CODE NEXT * , O(") CHARACTER
COUNTRY_OF_ORIGIN_CODE NEXT * , O(") CHARACTER
FREIGHT_TERMS_LOOKUP_CODE NEXT * , O(") CHARACTER
PAY_GROUP_LOOKUP_CODE NEXT * , O(") CHARACTER
PAY_DATE_BASIS_LOOKUP_CODE NEXT * , O(") CHARACTER
ALWAYS_TAKE_DISC_FLAG NEXT * , O(") CHARACTER
ORG_ID NEXT * , O(") CHARACTER
value used for ROWS parameter changed from 64 to 31
Record 1: Rejected - Error on table "AP"."AP_SUPPLIER_SITES_INT", column VENDOR_INTERFACE_ID.
ORA-01722: invalid number
Please guide me what could be an issue...
Is there any other way to pass function in sql loader..
Thanks and Regards
MuthukumarI created function like below...... retrun value as number
create or replace function VDR_INF_F(V_NUM number)
return number is
VDR_INF_id AP_SUPPLIERS_INT.VENDOR_INTERFACE_ID%type;
begin
select VENDOR_INTERFACE_ID
into VDR_INF_id
from AP_SUPPLIERS_INT
where CUSTOMER_NUM = V_NUM;
return VDR_INF_id;
end;
And attached that into loader program...
load data
infile *
into TABLE AP_SUPPLIER_SITES_INT
REPLACE
fields terminated by ","
OPTIONALLY ENCLOSED BY '"'
VENDOR_SITE_INTERFACE_ID "to_char(ap_supplier_sites_int_s.NEXTVAL)",
LAST_UPDATE_DATE "SYSDATE",
LAST_UPDATED_BY,
VENDOR_SITE_CODE,
CREATION_DATE "SYSDATE",
CREATED_BY,
PURCHASING_SITE_FLAG,
PAY_SITE_FLAG,
ADDRESS_LINE1,
ADDRESS_LINE2,
ADDRESS_LINE3,
CITY,
STATE,
ZIP,
COUNTRY,
PHONE,
FAX,
PAYMENT_METHOD_LOOKUP_CODE,
TERMS_ID,
CREATE_DEBIT_MEMO_FLAG,
HOLD_UNMATCHED_INVOICES_FLAG,
EMAIL_ADDRESS,
MATCH_OPTION,
EXCLUDE_FREIGHT_FROM_DISCOUNT,
INVOICE_CURRENCY_CODE,
PAYMENT_CURRENCY_CODE,
COUNTRY_OF_ORIGIN_CODE,
FREIGHT_TERMS_LOOKUP_CODE,
PAY_GROUP_LOOKUP_CODE,
PAY_DATE_BASIS_LOOKUP_CODE,
ALWAYS_TAKE_DISC_FLAG,
ORG_ID,
VENDOR_INTERFACE_ID expression "VDR_INF_F(':CUSTOMER_NUM')"
begindata
1005,,SYSDATE,1132,Test MA Site_1,SYSDATE,1132,Y,Y,No#907 62nd Street ,10th Sector,KK Nagar,Chennai,TamilNadu,600078,IN,+91 44 33333333,044 40404040,CHECK,10000,Y,N,[email protected],R,Y,INR,INR,IN,TBD,STANDARD,DISCOUNT,Y,120,1005
1005,,SYSDATE,1132,Test MA Site_2,SYSDATE,1132,Y,Y,No#907 62nd Street ,10th Sector,KK Nagar,Chennai,TamilNadu,600078,IN,+91 44 33333333,044 40404040,CHECK,10000,Y,N,[email protected],R,Y,INR,INR,IN,TBD,STANDARD,DISCOUNT,Y,120,1005
1005,,SYSDATE,1132,Test MA Site_3,SYSDATE,1132,Y,Y,No#907 62nd Street ,10th Sector,KK Nagar,Chennai,TamilNadu,600078,IN,+91 44 33333333,044 40404040,CHECK,10000,Y,N,[email protected],R,Y,INR,INR,IN,TBD,STANDARD,DISCOUNT,Y,120,1005
1006,,SYSDATE,1132,Test1 M Site_1,SYSDATE,1132,Y,Y,No#907 62nd Street ,10th Sector,KK Nagar,Chennai,TamilNadu,600078,IN,+91 44 33333333,044 40404040,CHECK,10000,Y,N,[email protected],R,Y,INR,INR,IN,TBD,STANDARD,DISCOUNT,Y,120,1006
1007,,SYSDATE,1132,Test1 B Site_1,SYSDATE,1132,Y,Y,No#907 62nd Street ,10th Sector,KK Nagar,Chennai,TamilNadu,600078,IN,+91 44 33333333,044 40404040,CHECK,10000,Y,N,[email protected],R,Y,INR,INR,IN,TBD,STANDARD,DISCOUNT,Y,120,1007
Even now sql loader giving same error..
like below.....
able "AP"."AP_SUPPLIER_SITES_INT", loaded from every logical record.
Insert option in effect for this table: REPLACE
Column Name Position Len Term Encl Datatype
VENDOR_SITE_INTERFACE_ID FIRST * , O(") CHARACTER
SQL string for column : "to_char(ap_supplier_sites_int_s.NEXTVAL)"
LAST_UPDATE_DATE NEXT * , O(") CHARACTER
SQL string for column : "SYSDATE"
LAST_UPDATED_BY NEXT * , O(") CHARACTER
VENDOR_SITE_CODE NEXT * , O(") CHARACTER
CREATION_DATE NEXT * , O(") CHARACTER
SQL string for column : "SYSDATE"
CREATED_BY NEXT * , O(") CHARACTER
PURCHASING_SITE_FLAG NEXT * , O(") CHARACTER
PAY_SITE_FLAG NEXT * , O(") CHARACTER
ADDRESS_LINE1 NEXT * , O(") CHARACTER
ADDRESS_LINE2 NEXT * , O(") CHARACTER
ADDRESS_LINE3 NEXT * , O(") CHARACTER
CITY NEXT * , O(") CHARACTER
STATE NEXT * , O(") CHARACTER
ZIP NEXT * , O(") CHARACTER
COUNTRY NEXT * , O(") CHARACTER
PHONE NEXT * , O(") CHARACTER
FAX NEXT * , O(") CHARACTER
PAYMENT_METHOD_LOOKUP_CODE NEXT * , O(") CHARACTER
TERMS_ID NEXT * , O(") CHARACTER
CREATE_DEBIT_MEMO_FLAG NEXT * , O(") CHARACTER
HOLD_UNMATCHED_INVOICES_FLAG NEXT * , O(") CHARACTER
EMAIL_ADDRESS NEXT * , O(") CHARACTER
MATCH_OPTION NEXT * , O(") CHARACTER
EXCLUDE_FREIGHT_FROM_DISCOUNT NEXT * , O(") CHARACTER
INVOICE_CURRENCY_CODE NEXT * , O(") CHARACTER
PAYMENT_CURRENCY_CODE NEXT * , O(") CHARACTER
COUNTRY_OF_ORIGIN_CODE NEXT * , O(") CHARACTER
FREIGHT_TERMS_LOOKUP_CODE NEXT * , O(") CHARACTER
PAY_GROUP_LOOKUP_CODE NEXT * , O(") CHARACTER
PAY_DATE_BASIS_LOOKUP_CODE NEXT * , O(") CHARACTER
ALWAYS_TAKE_DISC_FLAG NEXT * , O(") CHARACTER
ORG_ID NEXT * , O(") CHARACTER
VENDOR_INTERFACE_ID EXPRESSION
SQL string for column : "VDR_INF_F(':CUSTOMER_NUM')"
value used for ROWS parameter changed from 64 to 31
Record 1: Rejected - Error on table "AP"."AP_SUPPLIER_SITES_INT", column VENDOR_INTERFACE_ID.
ORA-01722: invalid number
Record 2: Rejected - Error on table "AP"."AP_SUPPLIER_SITES_INT", column VENDOR_INTERFACE_ID.
ORA-01722: invalid number
Record 3: Rejected - Error on table "AP"."AP_SUPPLIER_SITES_INT", column VENDOR_INTERFACE_ID.
ORA-01722: invalid number
Record 4: Rejected - Error on table "AP"."AP_SUPPLIER_SITES_INT", column VENDOR_INTERFACE_ID.
ORA-01722: invalid number
Record 5: Rejected - Error on table "AP"."AP_SUPPLIER_SITES_INT", column VENDOR_INTERFACE_ID.
ORA-01722: invalid number
Please guide me, how to clear this issue?
Thanks and Regards,
Muthu -
Hi All,
In our application, we are allowing user to upload data using excel sheet in UI.
We are using PHP script in UI and using SQL Loader to load data from excel sheet to temp_table.
The temp_table has a primary key.
Here my question is , Is there any way to put some batch id for every upload in that table in automatic way ?
so that we can easily extract the data by using batch id
we are using Oracle 11g.All that does is load a constant value, in which case you might as well just use constant 815 in your control file. If you want to automatically increment the value for each batch, then you need to use a different method.
Please see the example below. Prior to each data load, it loads the next value of the sequence into a separate table, then selects that value during the data load. Note that a SQL*Loader expression that uses select must be enclosed within parentheses within the double quotes.
SCOTT@orcl_11gR2> host type test1.dat
1 Prod1
2 Prod2
3 Prod3
4 Prod4
5 Prod5
SCOTT@orcl_11gR2> host type test2.dat
6 Prod6
7 Prod7
8 Prod8
SCOTT@orcl_11gR2> host type batch.ctl
options(load=1)
load data
replace
into table batch_tab
(batch_id expression "test_seq.nextval")
SCOTT@orcl_11gR2> host type data.ctl
load data
append
into table temp_table
fields terminated by whitespace
trailing nullcols
(p_id,
p_name,
batch_id expression "(select batch_id from batch_tab)")
SCOTT@orcl_11gR2> create table temp_table
2 (p_id number primary key,
3 p_name varchar2(6),
4 batch_id number)
5 /
Table created.
SCOTT@orcl_11gR2> create sequence test_seq
2 /
Sequence created.
SCOTT@orcl_11gR2> create table batch_tab
2 (batch_id number)
3 /
Table created.
SCOTT@orcl_11gR2> -- first load:
SCOTT@orcl_11gR2> host sqlldr scott/tiger control=batch.ctl log=batch1.log
SQL*Loader: Release 11.2.0.1.0 - Production on Fri Apr 19 17:16:33 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Commit point reached - logical record count 1
SCOTT@orcl_11gR2> host sqlldr scott/tiger control=data.ctl data=test1.dat log=test1.log
SQL*Loader: Release 11.2.0.1.0 - Production on Fri Apr 19 17:16:33 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Commit point reached - logical record count 5
SCOTT@orcl_11gR2> select * from batch_tab
2 /
BATCH_ID
1
1 row selected.
SCOTT@orcl_11gR2> select * from temp_table
2 /
P_ID P_NAME BATCH_ID
1 Prod1 1
2 Prod2 1
3 Prod3 1
4 Prod4 1
5 Prod5 1
5 rows selected.
SCOTT@orcl_11gR2> -- second load:
SCOTT@orcl_11gR2> host sqlldr scott/tiger control=batch.ctl log=batch2.log
SQL*Loader: Release 11.2.0.1.0 - Production on Fri Apr 19 17:16:33 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Commit point reached - logical record count 1
SCOTT@orcl_11gR2> host sqlldr scott/tiger control=data.ctl data=test2.dat log=test2.log
SQL*Loader: Release 11.2.0.1.0 - Production on Fri Apr 19 17:16:33 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Commit point reached - logical record count 3
SCOTT@orcl_11gR2> select * from batch_tab
2 /
BATCH_ID
2
1 row selected.
SCOTT@orcl_11gR2> select * from temp_table
2 /
P_ID P_NAME BATCH_ID
1 Prod1 1
2 Prod2 1
3 Prod3 1
4 Prod4 1
5 Prod5 1
6 Prod6 2
7 Prod7 2
8 Prod8 2
8 rows selected. -
Hi All,
Is there any way to call the sql loader in Apex to load the table with csv data.
Thanks in advance
DhanDo you need the application to load data for users as a function or are you just trying to load some data. Application Express has loading/unloading utilities from the main workspace menu that you can use for one time loads.
-
SQL Loader unicode (umlaut) problem
Hi
I want to load some data with SQL Loader. The data contains german umlaut like ä, ö, ü.
The loading process works, but the umlaut are transformed to something like 'ü' in the DB. How can I get to load them correctly?
My environment:
- DB 10g Rel.2
- Windows XP
- Registry key in Ora_Home: NLS_LANG=GERMAN_GERMANY.WE8MSWIN1252
I tried it with setting the character set in the CTL file:
characterset 'WE8MSWIN1252'
That didn't help either.
Does anyone have an idea? I searched the forum but didn't find a solution.
Thanks for your help,
RogerMaybe a codepage issue ? See this example :
C:\tmp>type umlaut.ctl
load data
infile umlaut.dat
replace
into table umlaut_tab
(a)
C:\tmp>sqlldr test/test control=umlaut.ctl
SQL*Loader: Release 10.2.0.1.0 - Production on Tue Jun 10 13:19:50 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Commit point reached - logical record count 2
Commit point reached - logical record count 3
C:\tmp>sqlplus test/test
SQL*Plus: Release 10.2.0.1.0 - Production on Tue Jun 10 13:19:56 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
SQL> select * from umlaut_tab;
A
õ
÷
³
SQL> exit
Disconnected from Oracle Database 10g Express Edition Release 10.2.0.1.0 - Produ
ction
C:\tmp>chcp 1252
Tabella codici attiva: 1252
C:\tmp>sqlplus test/test
SQL*Plus: Release 10.2.0.1.0 - Production on Tue Jun 10 13:20:19 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
SQL> select * from umlaut_tab;
A
ä
ö
ü
SQL> -
Hi,
Please could someone give me the syntax for expressing a where clause in SQL Loader control file? as an example i only want the data in the columns to be uploaded where person_id matches the person_id already present in the table.
My control file is below which needs amending to include a 'Where'. The append will also need changing i assume.
load data
infile '/app/DEV/appl/xxcpp/11.5.0/bin/TEST.csv'
APPEND
into table XXCPP_SQL_LOADER_TEST
fields terminated by "," optionally enclosed by '"'
( PERSON_ID, EMP_NAME, EMP_NUMBER, START_DATE DATE "fmDD/MM/RRRR" )
Many ThanksSQL*Loader has very limited conditional load capabilities. WHEN clause does not support OR (and it is documented). Anyway, you could do the following. Control file:
load data
infile *
APPEND
into table XXCPP_SQL_LOADER_TEST
When Person_id = '1'
fields terminated by "," optionally enclosed by '"'
( PERSON_ID POSITION(1), EMP_NAME, EMP_NUMBER, START_DATE DATE "fmDD/MM/RRRR" )
into table XXCPP_SQL_LOADER_TEST
When Person_id = '2'
fields terminated by "," optionally enclosed by '"'
( PERSON_ID POSITION(1), EMP_NAME, EMP_NUMBER, START_DATE DATE "fmDD/MM/RRRR" )
into table XXCPP_SQL_LOADER_TEST
When Person_id = '3'
fields terminated by "," optionally enclosed by '"'
( PERSON_ID POSITION(1), EMP_NAME, EMP_NUMBER, START_DATE DATE "fmDD/MM/RRRR" )
begindata
1,A,11,13/01/2011
2,B,12,13/01/2011
3,C,13,13/01/2011
4,D,14,13/01/2011
5,D,15,13/01/2011
{code}
Now:
{code}
SQL> select * from XXCPP_SQL_LOADER_TEST;
no rows selected
SQL> host sqlldr scott/tiger control=c:\temp\XXCPP_SQL_LOADER_TEST.CTL log=c:\temp\XXCPP_SQL_LOADER_TEST.LOG
SQL> select * from XXCPP_SQL_LOADER_TEST;
PERSON_ID EMP_NAME EMP_NUMBER START_DAT
1 A 11 13-JAN-11
2 B 12 13-JAN-11
3 C 13 13-JAN-11
SQL>
{code}
SY. -
SQL Loader Oracle 10g problem in upload date with time data -- Very urgent.
Hi
I am trying to upload data using SQL loader. There are three columns in the table
defined as DATE. When I tried upload a data like this '2007-02-15 15:10:20', it is not loading time part. The date stored as 02/15/2008' only. There is not time on that. I tried with many different format nothing work. Can please help me ?
I have also tried with to_date --> to_timestamp it did not work.
The application is going to be in production, I cannot change DATE to TIME STAMP. This is very urgent.
LASTWRITTEN "decode(:LASTWRITTEN,'null',Null, to_date(:LASTWRITTEN,'YYYY-MM-DD HH24:Mi:SS'))",
CREATEDON "decode(:CREATEDON,'null',Null, to_date(:CREATEDON,'YYYY-MM-DD HH24:Mi:SS'))",
LASTUPDATEDON(21) "decode(:LASTUPDATEDON,'null',Null, to_date(:LASTUPDATEDON(21),'DD/MM/YYYY HH24:MI:SS'))"Your problem is most likely in decode - the return type in your expression will be character based on first search value ('null'), so it will be implicitly converted to character and then again implicitly converted to date by loading into date column. At some of this conversions you probably are loosing your time part. You can try instead use cast:
SQL> desc t
Name Null? Type
LASTWRITTEN DATE
CREATEDON DATE
LASTUPDATEDON DATE
SQL> select * from t;
no rows selected
SQL> !cat t.ctl
LOAD DATA
INFILE *
INTO TABLE T
TRUNCATE
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' TRAILING NULLCOLS
LASTWRITTEN
"decode(:LASTWRITTEN,'null',cast(Null as date),
to_date(:LASTWRITTEN,'YYYY-MM-DD HH24:MI:SS'))",
CREATEDON
"decode(:CREATEDON,'null',cast(Null as date),
to_date(:CREATEDON,'YYYY-MM-DD HH24:MI:SS'))",
LASTUPDATEDON
"decode(:LASTUPDATEDON,'null',cast(Null as date),
to_date(:LASTUPDATEDON,'DD/MM/YYYY HH24:MI:SS'))"
BEGINDATA
2007-02-15 15:10:20,null,null
null,2007-02-15 15:10:20,null
null,null,15/02/2007 15:10:20
SQL> !sqlldr userid=scott/tiger control=t.ctl log=t.log
SQL*Loader: Release 10.2.0.3.0 - Production on Fri Feb 29 00:20:07 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Commit point reached - logical record count 3
SQL> select * from t;
LASTWRITTEN CREATEDON LASTUPDATEDON
15.02.2007 15:10:20
15.02.2007 15:10:20
15.02.2007 15:10:20Best regards
Maxim -
Sql loader using position and functions
Hi all, i need help loading some data in my table using sql loader. consider the following
CREATE TABLE er
a1 NUMBER,
a2 number,
a3 VARCHAR2(100),
a4 VARCHAR2(100),
a5 VARCHAR2(100),
a6 VARCHAR2(100),
a7 VARCHAR2(100),
a8 VARCHAR2(100)
OPTIONS (BINDSIZE=20548000, READSIZE=20548000, STREAMSIZE=20548000, DATE_CACHE=25000, SKIP=0)
LOAD DATA
INTO TABLE er
APPEND
TRAILING NULLCOLS
a1 POSITION(0001:0021) ,
a2 POSITION(0022:0042) "DECODE(SUBSTR(:a2,1,3),'***',NULL,:a2)" ,
a3 POSITION(0043:0053) ,
a4 POSITION(0054:0064) ,
a5 POSITION(0065:0075) ,
a6 POSITION(0076:0086) ,
a7 POSITION(0087:0093) "DECODE(SUBSTR(:a7,1,3),'***',NULL,:a7)"
BEGIN
0.00 ******************** X X X *X ****
END;if you look at the data, some fields have a lot of * and some has af few such as ****. i want to load this data into a table and when a field contain all * as a value, i want to set it to null. if a field contain a * and alphanumeric then that value should be load as it is.
in the example above, ******************** should be set to null and **** should also be set to null. notice that there is a field with X. since this field contain alpha numeric, it should be loaded into the table as is. the only time field should be set to null is when the value contain all .
somebody in this forum suggest using decode but it looks like it is not working and i get error when it reads second field and try to insert into a2 number column.
is there any way to use regular expression to find out if a field contain all *. also i want to trim each field since they might contain leading spaces.
can some one help with this using the sqlloader ctl and data above?You can include regular expression in you SQL*Loader control file.
An example can be found here:
http://www.morganslibrary.org/reference/sqlloader.html
Demos 7 and 8 using the UPPER and DECODE functions to illustrate how to do it. -
I am using sql loader to load a table
This is the syntax i am using
LOAD DATA
TRUNCATE
INTO TABLE selva_tst
WHEN(01:04) = 'D328' AND (06:06)='$'
FIELDS TERMINATED BY "|"
A_ID,
NULLIF(CO,$),
ANB,
STS_DT Date 'YYYYMMDD',
DMP_ID
It is giving error at line NULLIF(CO,$),
stating that syntax error in this line
can anyone help me in this regard
thanks in advanceYou may be interested to look up documentation about using sql expressions to load data.
http://download.oracle.com/docs/cd/B19306_01/server.102/b14215/ldr_field_list.htm#sthref1238
Best regards
Maxim -
i have to export flat file into oracle 10g database table with same datatypes as created in MS Access but during load i am facing following errors i don't know why,how can i handle this situation where as i created flate file and control file in same drive but sql* loader cannot find it.
control file
load data
infile 'F:\dumy.dat'
BADFILE 'F:\dumy.BAD'
DISCARDFILE 'F:\dumy.DSC'
APPEND
INTO TABLE dumy
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
(id INTEGER EXTERNAL,init_date sysdate 'mm/dd/yyyy mi:ss:hh',final_date date,
item varchar2(50))
*flat file*
1,12/22/2009 0:00:00,12/29/2009 0:00:00,"BRUSH"
2,12/22/2009 0:00:00,12/27/2009 0:00:00,"COMB"
all files are on f:\drive and i also copy control file in oracle home in BIN FOLDER
following error occur
SQL*Loader-500: Unable to open file (F:\DUM.CTL)
SQL*Loader-553: file not found
SQL*Loader-509: System error: The system cannot find the file specified.Here is something working with Oracle XE on Windows. All files are in the same directory C:\TMP and all commands are also run from C:\TMP:
c:\tmp>type dumy.sql
set echo on
select * from v$version;
drop table dumy purge;
create table dumy
id number,
init_date date,
final_date date,
item varchar2(50)
exit
c:\tmp>type dumy.ctl
load data
infile 'C:\tmp\dumy.dat'
BADFILE 'C:\tmp\dumy.BAD'
DISCARDFILE 'C:\tmp\dumy.DSC'
APPEND
INTO TABLE dumy
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
id integer external,
init_date date "mm-dd-yyyy hh24:mi:ss",
final_date date "mm-dd-yyyy hh24:mi:ss",
item char
c:\tmp>type dumy.dat
1,12/22/2009 0:00:00,12/29/2009 0:00:00,"BRUSH"
2,12/22/2009 0:00:00,12/27/2009 0:00:00,"COMB"
c:\tmp>sqlplus hr/hr @dumy
SQL*Plus: Release 10.2.0.1.0 - Production on Sat Mar 13 10:40:54 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
SQL> select * from v$version;
BANNER
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
SQL> drop table dumy purge;
Table dropped.
SQL>
SQL> create table dumy
2 (
3 id number,
4 init_date date,
5 final_date date,
6 item varchar2(50)
7 );
Table created.
SQL>
SQL> exit
Disconnected from Oracle Database 10g Express Edition Release 10.2.0.1.0 - Prod
ction
c:\tmp>sqlldr hr/hr control=dumy.ctl
SQL*Loader: Release 10.2.0.1.0 - Production on Sat Mar 13 10:41:00 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Commit point reached - logical record count 1
Commit point reached - logical record count 2
c:\tmp>type dumy.log
SQL*Loader: Release 10.2.0.1.0 - Production on Sat Mar 13 10:41:00 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Control File: dumy.ctl
Data File: C:\tmp\dumy.dat
Bad File: C:\tmp\dumy.BAD
Discard File: C:\tmp\dumy.DSC
(Allow all discards)
Number to load: ALL
Number to skip: 0
Errors allowed: 50
Bind array: 64 rows, maximum of 256000 bytes
Continuation: none specified
Path used: Conventional
Table DUMY, loaded from every logical record.
Insert option in effect for this table: APPEND
TRAILING NULLCOLS option in effect
Column Name Position Len Term Encl Datatype
ID FIRST * , O(") CHARACTER
INIT_DATE NEXT * , O(") DATE mm-dd-yyyy hh24:
i:ss
FINAL_DATE NEXT * , O(") DATE mm-dd-yyyy hh24:
i:ss
ITEM NEXT * , O(") CHARACTER
Table DUMY:
2 Rows successfully loaded.
0 Rows not loaded due to data errors.
0 Rows not loaded because all WHEN clauses were failed.
0 Rows not loaded because all fields were null.
Space allocated for bind array: 66048 bytes(64 rows)
Read buffer bytes: 1048576
Total logical records skipped: 0
Total logical records read: 2
Total logical records rejected: 0
Total logical records discarded: 0
Run began on Sat Mar 13 10:41:00 2010
Run ended on Sat Mar 13 10:41:01 2010
Elapsed time was: 00:00:00.89
CPU time was: 00:00:00.06
{code}
Do not use VARCHAR SQL*Loader data type which is not a portable data type but use CHAR instead.
Do not use SYSDATE if you want to load a date from your .dat file. -
SQL Loader with date formatting
Hi,
I'm trying to get sql loader to insert a date into a column. After much browsing, reading trial and error I still get an array of errors.
I'm using oracle XE
my control file looks like this
LOAD DATA
INFILE 'posmeters/meters.csv'
INTO TABLE position_meters
FIELDS terminated by ","
ID CONSTANT '0',
POSITION_ID,
DATETIME DATE "DD/MM/YYYY HH24:MI:SS",
CASH_IN,
CASH_OUT,
NOTES_IN,
CHANGE_OUT,
WINNINGS,
VTP,
REFILL,
TOKEN_IN,
TOKEN_OUT,
ELEC_PAY,
ELEC_CREDIT,
REMOTE_PAY,
REMOTE_CREDIT,
INSERT_TS EXPRESSION "TO_CHAR(SYSDATE, 'DD/MM/YYYY HH24:MI:SS')",
FIFTY_PND,
TWENTY_PND,
TEN_PND,
FIVE_PND,
TWO_PND,
ONE_PND,
FIFTY_P,
TWENTY_P,
TEN_P,
FIVE_P
It is the DATETIME field which gives me grief. I have a test data file that looks like this
0,1010,29/09/2011 10:23:24,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24
and my table is defined as follows
ID NUMBER NOT NULL,
POSITION_ID NUMBER,
DATETIME TIMESTAMP(6) DEFAULT localTIMESTAMP NOT NULL,
CASH_IN NUMBER,
CASH_OUT NUMBER,
NOTES_IN NUMBER,
CHANGE_OUT NUMBER,
WINNINGS NUMBER,
VTP NUMBER,
REFILL NUMBER,
TOKEN_IN NUMBER DEFAULT (0) NOT NULL,
TOKEN_OUT NUMBER DEFAULT (0) NOT NULL,
ELEC_PAY NUMBER DEFAULT (0) NOT NULL,
ELEC_CREDIT NUMBER DEFAULT (0) NOT NULL,
REMOTE_PAY NUMBER DEFAULT (0) NOT NULL,
REMOTE_CREDIT NUMBER DEFAULT (0) NOT NULL,
INSERT_TS TIMESTAMP(6) DEFAULT (localtimestamp) NOT NULL,
FIFTY_PND NUMBER DEFAULT 0,
TWENTY_PND NUMBER DEFAULT 0,
TEN_PND NUMBER DEFAULT 0,
FIVE_PND NUMBER DEFAULT 0,
TWO_PND NUMBER DEFAULT 0,
ONE_PND NUMBER DEFAULT 0,
FIFTY_P NUMBER DEFAULT 0,
TWENTY_P NUMBER DEFAULT 0,
TEN_P NUMBER DEFAULT 0,
FIVE_P NUMBER DEFAULT 0
I have tried defining the control file with
DATETIME DATE "DD/MM/YYYY HH24:MI:SS",
DATETIME EXPRESSION "TO_DATE(:DATETIME, 'DD/MM/YYYY HH24:MI:SS')",
DATETIME EXPRESSION "TO_TIMESTAMP(:DATETIME, 'DD/MM/YYYY HH24:MI:SS')",
I get errors such as
Record 1: Rejected - Error on table "SITE_MAIN"."POSITION_METERS", column DATETIME.
ORA-01861: literal does not match format string
SQL*Loader-291: Invalid bind variable DATETIME in SQL string for column DATETIME.
any help would greatfully appreciated.It seems that the problem was caused by the constant at the beginning of the record and had nothing to do with date formats.
My control file now looks like this
LOAD DATA
INFILE 'posmeters/meters.csv'
APPEND INTO TABLE position_meters
FIELDS terminated by ","
POSITION_ID ,
DATETIME date "DD/MM/YYYY HH24:MI:SS",
CASH_IN ,
CASH_OUT ,
NOTES_IN ,
CHANGE_OUT ,
WINNINGS ,
VTP ,
REFILL ,
TOKEN_IN ,
TOKEN_OUT ,
ELEC_PAY ,
ELEC_CREDIT ,
REMOTE_PAY ,
REMOTE_CREDIT ,
INSERT_TS "TO_TIMESTAMP(SYSDATE, 'DD/MM/YYYY HH24:MI:SS')",
FIFTY_PND ,
TWENTY_PND ,
TEN_PND ,
FIVE_PND ,
TWO_PND ,
ONE_PND ,
FIFTY_P ,
TWENTY_P ,
TEN_P ,
FIVE_P
all is good :o) -
Sql loader master detail tables
Hi
I am trying to load master detail tables using sql loader. I have a sequence in the master table as primary key and have to load primary key in detail table. is there any way i can query up the primary key by name in the control file. please whats the best way to do this.
can i query up the primary key in the master table by the name in detail table which is jan09.
e.g
master data
jan09,description
detail data
jan09,'test1','100,'y'
LOAD DATA
INFILE 'test.data'
insert
INTO TABLE master_table
fields terminated by ',' optionally enclosed by '"' trailing nullcols
(id position(1:2) "myseq.nextval",
code char,
creation_date date sysdate,
last_update_date date sysdate,
into TABLE BDETAILS
fields terminated by ',' optionally enclosed by '"' trailing nullcols
(id number "select id from master_table where code=" || :code
name char,
amt decimal,
flag char
)Hey Here is what you need.
You will have to understand and test this properly.
It took me quiet some time before i could get to this stage
Here is the test data with all the commands.
As far the ID in the detail table is concerned you have no option but to update that column once the loading is complete.
1) create Table
CREATE TABLE master_table(ID NUMBER,code VARCHAR2(50),creation DATE,last_update DATE);
CREATE TABLE bdetails(ID NUMBER,NAME VARCHAR2(100),amt NUMBER,flag VARCHAR2(10));
ALTER TABLE master_table ADD (chc VARCHAR2(10));2) Create Sequence
CREATE SEQUENCE testseq INCREMENT BY 1;3) CTL FILE
LOAD DATA
INFILE 'c:\sqlldr\test.txt' /*path of data file */
append
INTO TABLE master_table
when (1) ='M' /*to check if the record in the data file is a master record */
fields terminated by ',' optionally enclosed by '"' trailing nullcols
(id expression "testseq.nextval", /*select next value from sequence */
mcol1 filler, /*FILLER keyword is sused to skip first column from data file */
chc,
code ,
creation "sysdate",
last_update "sysdate"
Into TABLE BDETAILS
when (1) ='D' /*to check if the record in the data file is a Detail record */
fields terminated by ',' optionally enclosed by '"' trailing nullcols
(id expression "testseq.currval", /* UNFORTUNATELY THIS PICKS UP THE LAST ID OF THE MASTER RECORD SESSION STUFF GOING ON HERE*/
col1 filler position(1:2), /* specifying this POSITION(1:2) is very very important as you need to reset the cursor to start of the line for the next record */
name ,
amt ,
flag )4) SQLLDR Command
sqlldr scott/tiger data=c:\sqlldr\test.txt control=c:\sqlldr\1.ctl
5) data file
M,jan09,description
D,test1,100,y
M,feb09,description1
D,test2,200,x
M,mar09,description2
D,test3,200,xHope this helps you and give you a lead how to proceed.
Cheers!!!
Bhushan
Maybe you are looking for
-
Cost of Goods Sold Accounts by Region
Hi Friends, While doiing the GL settings base on Item Groups, there is an option to set the Revenue Account based on Domestic.EU.Foreign. Bu why is there no Cost of Goods of Sold accounts based on that. Is Cost of Goods Sold account use for calculati
-
Error in second local currency
Good evening, we have a problem in our system. We changed the country of the company for some problem in payment. The change effected on the second local currency so we ripristinate the originale country. In particular we have modified from IT to EG
-
Folks: I need to implement a load balancing solution pretty soon and I would like some ideas regarding topology, design and methodology. This is what I have: 1.) Two 7600 Aggregation routers with 4500 L2 server farm switches hanging off of them in a
-
see above Attachments: Garmin45.vi 621 KB timeset.bat 1 KB bargraph.llb 66 KB
-
How to update pre-installed apps in macbook pro?
I bought a macbook pro last middle of Oct-2014. It uses Maverick OS and has pre-installed apps like iMovie, iPhoto and GarageBand. Then the new OS Yosemite came. I updated my OS. Then I receive notice of updates for the said pre-installed apps. When