If that is the case, I would import the data to a temp table.
CREATE TABLE temp
(id varchar2(1),
Generic_num varchar2(20),
Generic_Name varchar2(20));
Then write a stored procedure to do the insert statements to your real
tables.
Declare a cursor of
Cursor cur is
SELECT * from temp;
And some variables to store your data:
V_dept_no varchar2(50);
Then, in your procedure body:
FOR cur_rec IN cur LOOP
IF cur_rec.id = '1 ' THEN
/*new department*/
V_dept_no:= cur_rec.generic_num;
INSERT INTO dept (deptno, deptname)
VALUES (cur_rec.generic_num, cur_rec.generic_name);
ELSIF cur_rec.id= '2 ' THEN
/*employee record*/
INSERT INTO emp ( deptno, empno, empname)
VALUES (V_dept_no, cur_rec.generic_num, cur_rec.generic_name);
END IF;
END LOOP;
COMMIT;
Please note:
This assumes that your first record is a department record and that the way
the data retrieved from the cursor is in the same order that it was in the
datafile used for the import.
HTH,
Melissa Paglia
-- --Original Message-- --
From: oracle-l-bounce@(protected) [ mailto:oracle-l-bounce@(protected)
<mailto:oracle-l-bounce@(protected) > ] On Behalf Of Kevin Lange
Sent: Wednesday, June 16, 2004 4:25 PM
To: 'oracle-l@(protected) '
Subject: SQL Loader Question on 8.1.7
Evening;
I figured if anyone would know ... you all would. Here is a simple
example given in the Oracle SQLLDR manual:
You have conditional data in a singl file to be loaded into different
tables:
Based on the Record ID, you want either the Department or the Employee
table to be loaded:
Into Table dept
When recid = 1
(recid Position(1:1) Integer External,
deptno Position(3:4) Integer External,
depname Position(8:21) Char)
Into Table emp
When recid = 2
(recid Position(1:1) Integer External,
empno Position(3:6) Integer External,
empname Position(8:17) Char
commission Position(19:25))
That is fairly simple.
It gets more difficult when you ask the question .... Can you carry the
data from one of the When sections over into another section ?? i.e. Is
there a way to make a presistant variable that is set in one section and
then used in another section ??
Using the sample above, we need to have the "Department Number " (depno)
inserted into the EMP table without having to add it to each individual
record where recid = 2 since it is already on the record where recid = 1.
Any help or direction to go for samples if possible would be greatly
appreciated.
Kevin
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------
Please see the official ORACLE-L FAQ: http://www.orafaq.com
<http://www.orafaq.com >
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------
To unsubscribe send email to: oracle-l-request@(protected)
put 'unsubscribe ' in the subject line.
--
Archives are at http://www.freelists.org/archives/oracle-l/
<http://www.freelists.org/archives/oracle-l/ >
FAQ is at http://www.freelists.org/help/fom-serve/cache/1.html
<http://www.freelists.org/help/fom-serve/cache/1.html >
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
"Bringing people together to advance their lives. "
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN " >
<HTML > <HEAD >
<META HTTP-EQUIV= "Content-Type " CONTENT= "text/html; charset=iso-8859-1 " >
<TITLE >RE: SQL Loader Question on 8.1.7 </TITLE >
<META content= "MSHTML 6.00.2800.1400 " name=GENERATOR > </HEAD >
<BODY >
<DIV > <SPAN class=349061422-16062004 > <FONT face=Arial color=#0000ff size=2 >You
are right. The dependent data (in this case Employee Data) always follows
the Parent Data (in this case the Department Data). Thats why I was
wondering if a variable could be set inside of SQLLDR to hold the data for the
"Department Number " from the Parent Data so it could be used in the Dependent
Data. </FONT > </SPAN > </DIV >
<DIV > <SPAN class=349061422-16062004 > <FONT face=Arial color=#0000ff
size=2 > </FONT > </SPAN > </DIV >
<DIV > <SPAN class=349061422-16062004 > <FONT face=Arial color=#0000ff size=2 >Of
couse a procedure could be written to do this just fine. But, all of
the facilities and dependent code already exists to make these loads using
SQLLDR. We wanted to do the least work possible i.e. only change a SQLLDR
control file intead of changing all the scripts that run
this. </FONT > </SPAN > </DIV >
<BLOCKQUOTE dir=ltr style= "MARGIN-RIGHT: 0px " >
<DIV class=OutlookMessageHeader dir=ltr align=left > <FONT face=Tahoma
size=2 >-- --Original Message-- -- <BR > <B >From: </B > Paglia, Melissa
[mailto:mpaglia@(protected)] <BR > <B >Sent: </B > Wednesday, June 16, 2004 5:03
PM <BR > <B >To: </B > oracle-l@(protected) <BR > <B >Subject: </B > RE: SQL Loader
Question on 8.1.7 <BR > <BR > </FONT > </DIV >
<P > <FONT size=2 >Hi Kevin- </FONT > </P >
<P > <FONT size=2 >From the sample data you provided, it looks like the only way
to know which department the employee is from is that the department precedes
the employee record. Not an easy relation. </FONT > </P >
<P > <FONT size=2 >If that is the case, I would import the data to a temp
table. </FONT > <BR > <FONT size=2 >CREATE TABLE temp </FONT > <BR > <FONT
size=2 > (id varchar2(1), </FONT > <BR > <FONT size=2 >
Generic_num varchar2(20), </FONT > <BR > <FONT size=2 >
Generic_Name varchar2(20)); </FONT > </P >
<P > <FONT size=2 > Then write a stored procedure to do the insert
statements to your real tables. </FONT > </P >
<P > <FONT size=2 >Declare a cursor of </FONT > <BR > <FONT size=2 > Cursor cur
is </FONT > <BR > <FONT size=2 > SELECT * from temp; </FONT >
<BR > <FONT size=2 >And some variables to store your data: </FONT > </P >
<P > <FONT size=2 >V_dept_no varchar2(50); </FONT > </P >
<P > <FONT size=2 >Then, in your procedure body: </FONT > </P >
<P > <FONT size=2 >FOR cur_rec IN cur LOOP </FONT > <BR > <FONT
size=2 > IF cur_rec.id = '1 ' THEN </FONT > <BR > <FONT
size=2 > /*new department*/ </FONT >
<BR > <FONT size=2 > V_dept_no:=
cur_rec.generic_num; </FONT > <BR > <FONT size=2 >
INSERT INTO dept (deptno, deptname) </FONT > <BR > <FONT
size=2 > VALUES (cur_rec.generic_num,
cur_rec.generic_name); </FONT > </P >
<P > <FONT size=2 > ELSIF cur_rec.id= '2 ' THEN </FONT > <BR > <FONT
size=2 > /*employee record*/ </FONT >
<BR > <FONT size=2 > INSERT INTO emp ( deptno,
empno, empname) </FONT > <BR > <FONT size=2 > VALUES
(V_dept_no, cur_rec.generic_num, cur_rec.generic_name); </FONT > <BR > <FONT
size=2 > END IF; </FONT > <BR > <FONT size=2 >END
LOOP; </FONT > <BR > <FONT size=2 >COMMIT; </FONT > </P >
<P > <FONT size=2 >Please note: </FONT > <BR > <FONT size=2 >This assumes that your
first record is a department record and that the way the data retrieved from
the cursor is in the same order that it was in the datafile used for the
import. </FONT > </P >
<P > <FONT size=2 >HTH, </FONT > <BR > <FONT size=2 >Melissa Paglia </FONT > </P >
<P > <FONT size=2 >-- --Original Message-- -- </FONT > <BR > <FONT size=2 >From:
oracle-l-bounce@(protected) [ <A
href= "mailto:oracle-l-bounce@(protected) " >mailto:oracle-l-bounce@(protected) </A >]
On Behalf Of Kevin Lange </FONT > <BR > <FONT size=2 >Sent: Wednesday, June 16,
2004 4:25 PM </FONT > <BR > <FONT size=2 >To: 'oracle-l@(protected) ' </FONT >
<BR > <FONT size=2 >Subject: SQL Loader Question on 8.1.7 </FONT > </P >
<P > <FONT size=2 >Evening; </FONT > <BR > <FONT size=2 > I figured if anyone
would know ... you all would. Here is a simple </FONT > <BR > <FONT
size=2 >example given in the Oracle SQLLDR manual: </FONT > </P >
<P > <FONT size=2 > You have conditional data in a singl file to be loaded
into different </FONT > <BR > <FONT size=2 >tables: </FONT > <BR > <FONT size=2 >
</FONT > <BR > <FONT size=2 > 1 50
Manufacturing </FONT > <BR > <FONT size=2 > 2 1100
Smith </FONT > <BR > <FONT size=2 > 2 1200
Snyder </FONT > <BR > <FONT size=2 > 1 60
Shipping </FONT > <BR > <FONT size=2 > 2 1121
Stevens </FONT > </P >
<P > <FONT size=2 > Based on the Record ID, you want either the Department
or the Employee </FONT > <BR > <FONT size=2 >table to be loaded: </FONT > </P >
<P > <FONT size=2 > Into Table dept </FONT > <BR > <FONT
size=2 > When recid = 1 </FONT > <BR > <FONT
size=2 > (recid Position(1:1) Integer
External, </FONT > <BR > <FONT size=2 > deptno
Position(3:4) Integer External, </FONT > <BR > <FONT
size=2 > depname Position(8:21)
Char) </FONT > <BR > <FONT size=2 > Into Table emp </FONT >
<BR > <FONT size=2 > When recid = 2 </FONT >
<BR > <FONT size=2 > (recid Position(1:1) Integer
External, </FONT > <BR > <FONT size=2 > empno
Position(3:6) Integer External, </FONT > <BR > <FONT
size=2 > empname Position(8:17) Char </FONT >
<BR > <FONT size=2 > commission
Position(19:25)) </FONT > </P >
<P > <FONT size=2 >That is fairly simple. </FONT > </P >
<P > <FONT size=2 >It gets more difficult when you ask the question
.... Can you carry the </FONT > <BR > <FONT size=2 >data from one of the When
sections over into another section ?? i.e. Is </FONT > <BR > <FONT
size=2 >there a way to make a presistant variable that is set in one section
and </FONT > <BR > <FONT size=2 >then used in another section ?? </FONT > <BR > <FONT
size=2 > </FONT > <BR > <FONT size=2 >Using the
sample above, we need to have the "Department Number " (depno) </FONT > <BR > <FONT
size=2 >inserted into the EMP table without having to add it to each
individual </FONT > <BR > <FONT size=2 >record where recid = 2 since it is already
on the record where recid = 1. </FONT > </P > <BR >
<P > <FONT size=2 >Any help or direction to go for samples if possible would be
greatly </FONT > <BR > <FONT size=2 >appreciated. </FONT > </P >
<P > <FONT size=2 >Kevin </FONT > <BR > <FONT
size=2 >-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------ </FONT >
<BR > <FONT size=2 >Please see the official ORACLE-L FAQ: <A
href= "http://www.orafaq.com " target=_blank >http://www.orafaq.com </A > </FONT >
<BR > <FONT
size=2 >-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------ </FONT >
<BR > <FONT size=2 >To unsubscribe send email to:
oracle-l-request@(protected) </FONT > <BR > <FONT size=2 >put 'unsubscribe ' in
the subject line. </FONT > <BR > <FONT size=2 >-- </FONT > <BR > <FONT size=2 >Archives
are at <A href= "http://www.freelists.org/archives/oracle-l/ "
target=_blank >http://www.freelists.org/archives/oracle-l/ </A > </FONT > <BR > <FONT
size=2 >FAQ is at <A
href= "http://www.freelists.org/help/fom-serve/cache/1.html "
target=_blank >http://www.freelists.org/help/fom-serve/cache/1.html </A > </FONT >
<BR > <FONT
size=2 >-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -- </FONT >
</P > <BR >
<P > <I > <B > <FONT size=2 > "Bringing people together to advance their
lives. " </FONT > </B > </I > </P > </BLOCKQUOTE > </BODY > </HTML >
-- ---_=_NextPart_001_01C453EF.9D4488A0--
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------
To unsubscribe send email to: oracle-l-request@(protected)
put 'unsubscribe ' in the subject line.
--
Archives are at http://www.freelists.org/archives/oracle-l/
FAQ is at http://www.freelists.org/help/fom-serve/cache/1.html
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --