Q : SQL*Loader : Loading on a condition
Hi,
Appreciate if someone can give me some directions on this.
I get data-files which has a particular identified on the 1st record( header ), based on which I've to load a constant for the 1st column of every row. How do I set in the control file.
Example :-
data_file_1
O|08-aug-04|1000 -- format( company_id|date|row_count )
john saylor|100|10000 --format( name|emp_id|salary )
larry ellisson|1|10000000 --format( name|emp_id|salary )
... -- 1000 such records
data_file_2
S|08-aug-04|10
scott mcnealy|1|1000000
john schwartz|2|1000000
--10 such records
The table I want to load these 2, have these columns
Table A
Company_name
Emp_name
Emp_id
Run_date ( default to sysdate )
Now, all data-files will have only one identifier-record and in the 1st row. So in these examples, I've to set a constant as Oracle or Sun Microsystems based on the 1st record( header ) for every row inserted from that data-file. I need to embed all these in a single control-file to load data-files for different companies.
Thanks.
- Shankar.
Here's one way, which involves creating a separate table to store the header record:
http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:12476473797898
Similar Messages
-
SQL*Loader-273: READBUFFERS may be used only in direct path.
Hi,
I am trying to upgrade from OWB 10G to 11G. y map from flat file to stage maps work fine in 10G. when i upgrade the maps to 11G i get the error:
Error
RPE-01013: SQL Loader reported error condition, number 1.
SQL*Loader: Release 11.1.0.7.0 - Production on Fri May 8 15:10:20 2009
Copyright (c) 1982, 2007, Oracle. All rights reserved.
SQL*Loader-273: READBUFFERS may be used only in direct path.
SQL*Loader: Release 11.1.0.7.0 - Production on Fri May 8 15:10:20 2009
Copyright (c) 1982, 2007, Oracle. All rights reserved.
SQL*Loader-273: READBUFFERS may be used only in direct path.
if i go to configure and make the READBUFFERS to = 0 then the map works fine. this used to work fine in 10G. I compared the .CTL file of sql loder and i notice the 10G sql loader file did not care for this property being set. while in 11G .ctl file i see the readbuffer property being set. though i can make the map run in 11G i can not go to each map and then reset it. ...Please help.
ThanksIN 10 G environment
a.)Direct path = False.
b.) Read buffers = 4 (defaults to 4)
10G Code generated :
-- Oracle Warehouse Builder
-- Generator Version : 10.1.0.4.0
-- Created Date : Mon May 11 10:16:31 CDT 2009
-- Modified Date : Mon May 11 10:16:31 CDT 2009
-- Created By : owb_repository
-- Modified By : owb_repository
-- Generated Object Type : SQL*Loader Control File
-- Generated Object Name : GFHGF
-- © 2003 Oracle Corporation. All Rights Reserved.
OPTIONS ( ERRORS=50, BINDSIZE=50000, ROWS=200, READSIZE=65536)
LOAD DATA
CHARACTERSET WE8MSWIN1252
INFILE 'C:\EAND.dat'
INTO TABLE "{{ORACLE10G.Schema}}"."EAND"
APPEND
REENABLE DISABLED_CONSTRAINTS
FIELDS
"PERSON_SSN_SOURCE" POSITION (3:3) CHAR
IN 11 G environment
a.)Direct path = False.
b.) Read buffers = 4 (for new maps crated defaults to 0)
-- Generator Version : 11.1.0.7.0
-- Created Date : Mon May 11 10:06:37 CDT 2009
-- Modified Date : Mon May 11 10:06:37 CDT 2009
-- Created By : OWB_WUSER
-- Modified By : OWB_WUSER
-- Generated Object Type : SQL*Loader Control File
-- Generated Object Name : "GFHGF"
-- Copyright © 2000, 2007, Oracle. All rights reserved.
OPTIONS (BINDSIZE=50000,ERRORS=50,ROWS=200,READSIZE=65536)
LOAD DATA
CHARACTERSET WE8MSWIN1252
INFILE '{{ETL_FILE_LOC.RootPath}}{{}}EAND.dat''
BADFILE '{{ETL_FILE_LOC.RootPath}}{{}}EAND'
READBUFFERS 4
CONCATENATE 1
INTO TABLE "STAG"."EAND"
TRUNCATE
REENABLE DISABLED_CONSTRAINTS
"PERSON_SSN_SOURCE" POSITION (3:3) CHAR
my question is even as both the properties in 10G and 11G are same why does .ctl file generated in 11G has statement "READBUFFERS 4" while this is neglected in owb 10G generated .ctl file? Please Help.
Edited by: user591315 on May 11, 2009 8:14 AM
Edited by: user591315 on May 11, 2009 8:16 AM -
SQL Loader error number 1 in OWB 9.0.4
I'm trying to execute a flat-file to database table mapping (using SQL*Loader), having set up my locations & connectors. When I execute the mapping, I get the following message:
Starting Execution COM_COM_MT_STG
Starting Task COM_COM_MT_STG
RPE-1013-SQL_LOADER_ERROR SQL Loader reported error condition, number 1.
Completing Task COM_COM_MT_STG
Completing Execution COM_COM_MT_STG
What does that mean and how do I fix it?
Also, is there any detailed documentation on building such a mapping, that can take you through all the steps, from creating the flat file module to deployment?
Thanks,
CareyCarey,
Use the runtime audit browser to access the error log. It will show you what went wrong. You may have to re-register your flat file location with a folder separator at the end... This is a bug.
Thanks,
Mark. -
How to have more than one condition on same column --- using SQL Loader
Hi All,
I am stuck with SQL Loader..
How do I filter records before loading in the table using when clause..
i should load data only when
field1 = 'AC' or 'VC'
field2 is NULL
i used various combinations in when clause like
a) when field1='AC' or field1='VC' and field2 = BLANKS
b) when (field1='AC') and (field2 = BLANKS )
& similar...
In all the cases I tried I could not implement OR condition with field1 and null condition with field2
but my main concern is can we use OR or IS NULL things in when clause of SQL Loader..
is it possible to check this anywhere??
any alternate solution u could suggest??
Thanks
DikshitOk I'll try that, although I did try it earlier when I had iTunes 5.xx loaded, I think.
As to size of playlists, I have a master (900 songs) that defines what will fit onto the ipod , I then generate all the others as subsets of the master (not of the library)- hence I know they will all fit
Can you also clarify something for me: the dialogue box we are discussing is intended, I think, so that one can set the automatic synching of certain playlists between the PC & the ipod. Is that the only way one can select other playlists to go to the ipod - i.e. as static once-offs, not synchronised ?
Apple' docs, I think, are poor in this regard - they assume most ipods are bigger then the users song library and they gloss over the details of this alternate mode of playlist synching.
Thanks - Nick -
How to use Conditional statements in SQL Loader control file
Hi,
I am using sql loader to load a flat file to the table. I am using control file for this purpose as show below:
LOAD
INTO TABLE store_shrink
TRUNCATE
FIELDS TERMINATED BY " "
TRAILING NULLCOLS
SITE_ID char,
ST_SHRINK char,
ST_REVENUE char,
SHRINK_PR char ":ST_SHRINK/:ST_REVENUE"
My question is this. If in the flat file the value of 'ST_REVENUE' is '0', then I want 'SHRINK_PR' to be '0' as well, and skip the calculation (:st_shrink/:st_revenue).
How to achieve this with the conditional statement or using any Oracle function?
Any help or suggestion is greatly appreciated.
Thanks in advance.Hi there,
I tried the following in my above query and it doesn't work somehow. Anyone has an idea? I have been on internet throughout but to no avail. Please help:
LOAD
INTO TABLE store_shrink
TRUNCATE
FIELDS TERMINATED BY " "
TRAILING NULLCOLS
SITE_ID char,
ST_SHRINK char,
ST_REVENUE char,
SHRINK_PR char "case (when :st_revenue<>'0.00' then :SHRINK_PR=:ST_SHRINK/:ST_REVENUE else :SHRINK_PR='0.00') end"
) -
SQL Loader - Conditional Data Loading
Hello Friends,
I am trying to use SQL Loader to load the following records in to the Emp table (columns being - empno, ename, job, mgr, hiredate, sal, comm, deptno ).
7876,ADAMS,CLERK,7788,"23-MAY-87",1100,,20
7900,JAMES,CLERK,7698,"03-DEC-81",950,,30
7902,FORD,ANALYST,7566,"03-DEC-81",3000,,20
7934,MILLER,CLERK,7782,"23-JAN-82",1300,,10
I want to put a condition that the data should be loaded only when the 5th field in the record (i.e, the Hiredate field) should be greater than "01-JAN-82". So with this condition, the only records to be loaded are the 1st, and the 4th one... the other two records have the hiredates being less than "01-JAN-82".
load data
infile 'c:\mydata.csv'
into table emp1
when .....
fields terminated by "," optionally enclosed by '"'
( empno, ename, job, mgr, hiredate, sal, comm, deptno )
I am unable to put the when condition in the control file above and would be grateful if you kindly can give me some pointer as to how to achieve this.
Thanks and Regards.
Edited by: user645883 on Dec 29, 2008 12:45 AMHello Friends,
Thanks for your replies.
The examples only show the when clauses where we can only use "=" or "<>" in the clause. I am trying to see if we can use ">=" or "<=" in the when clause to load the conditional data. Also trying to find out if date fields can be compared in the when clause. I am unable to do so till now and it throws syntax errors everytime
I am able to test the when with string literals and with "=" and "<>" conditions though.
Please help.
Thanks & Regards. -
Sql*loader - load data in table with multiple condition
Hi,
I have oracle 9i on Sun sloaris and i need to load data in one of oracle table using sql*loader with conditional column data.
My table is like:
Load_table
col1 varchar2(10),
col2 varchar2(10),
col3 varchar2(10),
Now i have to load data like:
If col2 = US1 then col3 = 'AA'
If col2 = US2 then col3 = 'BB'
If col2 = US3 then col3 = 'CC'
How can i load this data in table using sql*loader?
Thanks,
PoraHi
it is a half-solution.
You have to:
1. open file
2. take a line
3. split the line into values (using substring to)
4. check condition (01 or 02)
5. do a proper insertion
Good Luck,
Przemek
DECLARE
v_dir VARCHAR2(50) := 'd:/tmp/'; --directory where file is placed
v_file VARCHAR2(50) := 'test.txt'; -- file name
v_fhandle UTL_FILE.FILE_TYPE; ---file handler
v_fline VARCHAR2(906); --file line
v_check VARCHAR2(50);
BEGIN
v_fhandle := UTL_FILE.FOPEN(v_dir, v_file, 'R'); --open file for read only
LOOP -- in the loop
UTL_FILE.GET_LINE( v_fhandle , v_fline); -- get line by line from file
if (substr(v_fline,17,2) = '01') then --check the value
INSERT INTO ... -- Time_in
else
INSERT INTO ... -- Time_out
end if;
END LOOP;
EXCEPTION
WHEN NO_DATA_FOUND
THEN UTL_FILE.FCLOSE( v_fhandle );
END; -
Using SQL Loader to insert data based on conditionally statements
I would like to use sql loader to insert records from a single text file into an Oracle database table. Sounds easy but the problem is that I need to check the existence of data in another table (Table A) before data can be loaded into Table B.
Table A has two columns: dept_no (primary key value) and dept_name (char)
Table B has five columns: emp_no (primary key value), dept_no (foreign key value to Table A), employee (char), job_title (char) and salary (number)
Text File looks like this:
Finance Jones President 10000
HR Smith Admin 2000
HelpDesk Jenkins Technician 3000
Problem:
1. I need sql loader to insert records into Table B by first checking if the first field in the file is in Table A.
2. If value exists get it's dept_no value.
3. If value doesn't exist discard record ( I might want to have sql loader insert a new record for this into Table A)
4. Using value from #2, insert the value in Table B for dept_no column.
5. Also assign a sequence value for the emp_no value in Table B.
Any guidance is greatly appreciated.
Thanks,Hello,
I am not sure this is possible with SQL loader. I would rather use an external table based on your file.
Then, I would use SQL to load your data into your table, based on your conditions.
Your request is not very complicated, writing the SQL to do that will be really more simple than trying to do it with SQL loader.
Hope it will help.
Regards,
Sylvie -
SQL LOader and conditional load
Hi guys is there any way that I can insert a record in a table B based on the date in a header record in a text file .
The flow in the SQL Loader control file should be
Load the text file T to a table say A
insert a record in table B based on the date in header record in text file T.Example if date is less than 10 Aug 2007 then B.version should be Y or else N.
Thanks
MThis can easily be done using External Tables.
You create an external table on 'text file' and then do something like this:
insert into B
select case date > '10 aug 2007' when true then Y else N end
from table external_table
where (your where clause here)..
Does this help? -
Hi. I'm currently using the When option in my SQL Loader script:
when (01:07) <> '9000001'But now I'm finding I need to exclude multiple strings '9000001', '9000002','9000003','9000004'. Is there a way to do this? Any help would be greatly appreciated.sharpe wrote:
Awesome. Thanks. One last question...if I have these strings (e.g. '9000001', etc...) stored in a different table is there anyway to reject records where this value is in my table? Something like a nested select statement?
when (01:07) not in(select mystr from mytable)Let me know is referencing a table is possible or not. Thanks.As far as I know, you can't do that. I believe the operator has to be either = or != and the value to compare has to be a literal, not a select or function or expression. You could use either SQL*Loader (or an external table if your data is on the server not the client) to load the data into a staging table, then use SQL to insert ... where ... not in(select mystr from mytable). -
SQL*LOADER Conditional using conventional method
I need load only the registers that have one determined value,
using SQL*LOADER with conventional method.
thanksHave you looked at the WHEN clause?
eg.
INTO TABLE dept
WHEN recid = 1
( recid ... etc -
Loading two tables at same time with SQL Loader
I have two tables I would like to populate from a file C:\my_data_file.txt.
Many of the columns I am loading into both tables but there are a handful of columns I do not want. The first column I do not want for either table. My problem is how I can direct SQL Loader to go back to the first column and skip over it. I had tried using POSITION(1) and FILLER for the first column while loading the second table but I got THE following error message:
SQL*Loader-350: Syntax error at line 65
Expecting "," or ")" found keyword Filler
col_a Poistion(1) FILLER INTEGER EXTERNALMy control file looks like the following:
LOAD DATA
INFILE 'C:\my_data_file.txt'
BADFILE 'C:\my_data_file.txt'
DISCARDFILE 'C:\my_data_file.txt'
TRUNCATE INTO TABLE table_one
WHEN (specific conditions)
FIELDS TERMINATED BY ' '
TRAILING NULLCOLS
col_a FILLER INTEGER EXTERNAL,
col_b INTEGER EXTERNAL,
col_g FILLER CHAR,
col_h CHAR,
col_date DATE "yyyy-mm-dd"
INTO TABLE table_two
WHEN (specific conditions)
FIELDS TERMINATED BY ' '
TRAILING NULLCOLS
col_a POSITION(1) FILLER INTEGER EXTERNAL,
col_b INTEGER EXTERNAL,
col_g FILLER CHAR,
col_h CHAR,
col_date DATE "yyyy-mm-dd"
)Try adapting this for your scenario.
tables for the test
create table test1 ( fld1 varchar2(20), fld2 integer, fld3 varchar2(20) );
create table test2 ( fld1 varchar2(20), fld2 integer, fld3 varchar2(20) );
control file
LOAD DATA
INFILE "test.txt"
INTO TABLE user.test1 TRUNCATE
WHEN RECID = '1'
FIELDS TERMINATED BY ' '
recid filler integer external,
fld1 char,
fld2 integer external,
fld3 char
INTO TABLE user.test2 TRUNCATE
WHEN RECID <> '1'
FIELDS TERMINATED BY ' '
recid filler position(1) integer external,
fld1 char,
fld2 integer external,
fld3 char
data for loading [text.txt]
1 AAAAA 11111 IIIII
2 BBBBB 22222 JJJJJ
1 CCCCC 33333 KKKKK
2 DDDDD 44444 LLLLL
1 EEEEE 55555 MMMMM
2 FFFFF 66666 NNNNN
1 GGGGG 77777 OOOOO
2 HHHHH 88888 PPPPP
HTH
RK -
Loading multiple tables with SQL Loader
Hi,
I want to load multiple tables from a single data file using SQL Loader.
Here's the basic idea of what I want. Let's say I have two tables, table =T1
and table T2:
SQL> desc T1;
COL1 VARCHAR2(20)
COL2 VARCHAR2(20)
SQL> desc T2;
COL1 VARCHAR2(20)
COL2 VARCHAR2(20)
COL3 VARCHAR2(20)
My data file, test.dat, looks like this:
AAA|KBA
BBR|BBCC|CCC
NNN|BBBN|NNA
I want to load the first record into T1, and the second and third record load into T2. How do I set up my control file to do that?
Thank!Tough Job
LOAD DATA
truncate
INTO table t1
when col3 = 'dummy'
FIELDS TERMINATED BY '|'
TRAILING NULLCOLS
(col1,col2,col3 filler char nullif col3='dummy')
INTO table t2
when col3 != 'dummy'
FIELDS TERMINATED BY '|'
(col1,col2,col3 nullif col3='dummy')
This will load t2 tbl but not t1.
T1 Filler col3 is not accepting nullif. Its diff to compare columns have null using when condition. If i find something i will let you know.
Can you seperate records into 2 file. Will a UNIX command work for you which will seperate 2col and 3col record types for you. and then you can execute 2 controlfiles on it.
Thanks,
http://www.askyogesh.com -
SQL *Loader and External Table
Hi,
Can anyone tell me the difference between SQL* Loader and External table?
What are the conditions under we can use SQL * Loader and External Table.
ThanxExternal tables are accessible from SQL, which generally simplifies life if the data files are physically located on the database server since you don't have to coordinate a call to an external SQL*Loader script with other PL/SQL processing. Under the covers, external tables are normally just invoking SQL*Loader.
SQL*Loader is more appropriate if the data files are on a different server or if it is easier to call an executable rather than calling PL/SQL (i.e. if you have a batch file that runs on a server other than the database server that wants to FTP a data file from a FTP server and then load the data into Oracle).
Justin -
Substitution for logical OR usage in control file of sql loader
Hi,
can anyone suggest me a substituion method to use the functionality of logical OR in control file developed for sql loader.
Ex:
load data
append
into table ABC
when (1:2) = 'AD'
--AND ((27:28)= '01' OR (27:28)= '02')
AND (1222:1222) = '1'
trailing nullcols
Note: condition commented in the above example need to be replaced.
one way of doing it can be splitting blocks for each condition.
Then it will look like:
load data
append
into table ABC
when (1:2) = 'AD'
AND (27:28)= '01'
AND (1222:1222) = '1'
trailing nullcols
into table ABC
when (1:2) = 'AD'
AND (27:28)= '02'
AND (1222:1222) = '1'
trailing nullcols
So, i'm looking for a better way than this, as i cannot work with the above
splitting logic because i'm dealing with lot many conditions.
Thanx inadvance
KishoreHi,
can anyone suggest me a substituion method to use the functionality of logical OR in control file developed for sql loader.
Ex:
load data
append
into table ABC
when (1:2) = 'AD'
--AND ((27:28)= '01' OR (27:28)= '02')
AND (1222:1222) = '1'
trailing nullcols
Note: condition commented in the above example need to be replaced.
one way of doing it can be splitting blocks for each condition.
Then it will look like:
load data
append
into table ABC
when (1:2) = 'AD'
AND (27:28)= '01'
AND (1222:1222) = '1'
trailing nullcols
into table ABC
when (1:2) = 'AD'
AND (27:28)= '02'
AND (1222:1222) = '1'
trailing nullcols
So, i'm looking for a better way than this, as i cannot work with the above
splitting logic because i'm dealing with lot many conditions.
Thanx inadvance
Kishore -
SQL*Loader - How to combine 2 controlfiles to one controlfile
I have several controllfiles which each import another table from another datafile, because I don't want execute every seperat or create a batch file.... I'm looking for a way to put they all in one single controlfile.
example:
1st ctl-file:
LOAD DATA
INFILE "t1.dat"
INTO TABLE t1 REPLACE
FIELDS TERMINATED BY " "
(c1,
c2 "to_number(:c2,'99999999999999999.99999999999999999','NLS_NUMERIC_CHARACTERS=''.,''')",
c3 date 'YYYY-MM-DD"T"HH24:MI:SS')
gQuqT 478.60636734965914 2006-12-05T11:00:49
ÜgQK 963.0277916962095 2006-12-30T08:03:00
üZfxN 465.15226622488257 2006-12-30T09:14:12
2nd ctl-file:
LOAD DATA
INFILE "t2.dat"
INTO TABLE t2 REPLACE
FIELDS TERMINATED BY " "
(c1,
c2 "to_number(:c2,'99999999999999999.99999999999999999','NLS_NUMERIC_CHARACTERS=''.,''')")
alvwxs 13.0
poeh 15.0
zpgiht 21.0
At the examples is everytime used a id column, to ident which row should import in which table.
But at my case i need something like a where condition from which file the data should be imported....how should it look?
Can someone give me an advice how a controlfile should look which import both tables in one controlfile?
BR
rolandIt is not possible to combine the last 3 columns as those columns are seperated by commas and in the SQL Loader control file you must ve specified COMMA as an delimiter. So u better have all the columns in the table plus add one more column which holds the concatenation of the 3 columns.
Vijay
Maybe you are looking for
-
Q : How to restore from USB if restore partition is removed?
Hi, have made a backup of my Windows 7 cumputer envy 14 spectre to a usb drive with hp recovery manager. After i deleted the restore partition on the drive, and installed Windows 8. Now having sleep/power issues on Windows 8, have to go back to Windo
-
Tag to take a java class in JSP page
Hi, � need to get a tag to get a java class for example Test.java into a JSP page like MyJSP.jsp so that � can ,after doing this, call its methods, variables etc. Thank you !
-
Sql query: number of occurence of cellData on more thann one column in tabl
I have employee table contains following rows. INSERT INTO employee VALUES (105, 'Srinath','vijay','Aeronautics', 27, 33000); INSERT INTO employee VALUES (105, 'Kumble','Anil','Aeronautics', 27, 33000); INSERT INTO employee VALUES (105, 'Prabhakar','
-
We have a running application which uses Weblogic Server 6.1. We wanted to download an evaluation copy of 6.1 from one of our other centers to try and run the same application. However, on going to the site I find that only 8.1 (or 7.0) is available
-
Error while installing sybase powerbuilder 12.5.2 standard runtime
Hi Folks: I was trying to install PB 12.5 runtime package (PBCLTRT125.msi) as "Run as elevated" on Win 7 64 bit VM and I got below error: Module C:\Program Files(x86)\Sybase\Shared\PowerBuilder\pbjvm125.dll failed to register.HRESULT -2147024770. Con