Home » RDBMS Server » Server Utilities » SQL-Loader+ Big Problem
SQL-Loader+ Big Problem [message #154932] Wed, 11 January 2006 07:23 Go to next message
galaxy
Messages: 62
Registered: October 2005
Member
Hello,

I think this is a difficult Question:

This shows how our file looks like:

B1,YYY,bbb,bbb,bbb,bbb,bbb,bbb
H2,ccc,ccc,cc,ccd
H2,ccc,ccc,cc,ccd
B1,XXX,ddd,ddd,ddd,ddd,ddd,ddd
H2,ccc,ccc,ccc,cca
H2,ccc,ccc,ccc,cca

Now the Problem:

I want to load this file in our database (It is an Oracle 8.1.7)
In the Database it should have the following structure:

H2|ccc|ccc|cc|ccd|YYY
H2|ccc|ccc|cc|ccd|YYY
H2|ccc|ccc|ccc|cca|XXX
H2|ccc|ccc|ccc|cca|XXX

So, all H2 lines should be load in the database and in the last column of the database table should be an entry from each B1 row
(in this case XXX and YYY) which identifies it with the correct B1.

Is this possible??

I don't know how to make the insert with the B1 value (treat it like a constant) until the next B1 value of the file is reached. Then this should be inserted, and so on.

Can somebody help me?
Re: SQL-Loader+ Big Problem [message #154940 is a reply to message #154932] Wed, 11 January 2006 07:53 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10707
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
Easiest method is to load data as-is into a staging table and use sql means to get data from staging table into your target table.
or
manupulating your datafile with OS means.
So within sql*loader methods, you do not want to load B1 values. Right?
Re: SQL-Loader+ Big Problem [message #154942 is a reply to message #154932] Wed, 11 January 2006 07:59 Go to previous messageGo to next message
galaxy
Messages: 62
Registered: October 2005
Member
After each row of H2 i want one value (in my example the XXX or YYY) from B1. B1 is the "Headlien for each Part. So I want to identify each H2 line with its correct Headline"
Re: SQL-Loader+ Big Problem [message #154945 is a reply to message #154942] Wed, 11 January 2006 08:10 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10707
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
how would you differentiate ( a header record and tail record)?
number of columns?
In the example you have given, B1 is header and first column is constant which makes things easy.Is that so in real time also?.

Re: SQL-Loader+ Big Problem [message #154951 is a reply to message #154932] Wed, 11 January 2006 08:30 Go to previous messageGo to next message
galaxy
Messages: 62
Registered: October 2005
Member
I will try again.

The whole is an csv File.
There are many rows with an entry H2 at the beginning. each entry line goes about 13 columns.

Between these "H2 lines" there are about 50 lines which start with B1 in the first column (B1,...,...,..).

And now I want to load all the H2 data in a database table.
after EACH line of H2 should be a value (XXX,YYY,...) from the line B1 which is in front of the H2 data. So i can later identifie which H2 Belongs to which B1(= Headline).

No Header and tail reocrd or number of lines.
Only columns in a csv File
Re: SQL-Loader+ Big Problem [message #154969 is a reply to message #154951] Wed, 11 January 2006 09:39 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10707
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
I am not aware of any pure sqlldr method.
Either load data as-is and use sql means
or
manipulate your datafile before loading.
Something like this. If you can use PERL, this would be much easier.
-- My original datafile
oracle@mutation#cat mydatafile
B1,xxx,bbb,bbb,bbb,bbb,bbb,bbb
H2,ccc,ccc,cc,cca
H2,ccc,ccc,cc,ccb
B1,yyyy,ddd,ddd,ddd,ddd,ddd,ddd
H2,ccc,ccc,ccc,ccc
B1,zzz,ddd,ddd,ddd,ddd,ddd,ddd
H2,ccc,ccc,ccc,ccd

--  SOMESCRIPT is the script i used
--
oracle@mutation#somescript
*********NewDatafileIs*****
H2,ccc,ccc,cc,cca,xxx
H2,ccc,ccc,cc,ccb,xxx
H2,ccc,ccc,ccc,ccc,yyyy
H2,ccc,ccc,ccc,ccd,zzz

-- source for somescript
--
oracle@mutation#cat somescript
cat mydatafile | while read thisline
do
 HD=`echo $thisline | awk -F',' '{print $1}'`
 if [ "$HD" = "B1" ]; then
 HT=`echo $thisline | awk -F',' '{print $2}'`
 else
   echo $thisline,$HT  >> /tmp/newdatafile
 fi
done
echo "*********NewDatafileIs*****"
cat /tmp/newdatafile
#-- use sqlldr to load this /tmp/newdatafile
#-- after loading rename/move/remove the newdatafile
rm /tmp/newdatafile
oracle@mutation#
Re: SQL-Loader+ Big Problem [message #155066 is a reply to message #154969] Thu, 12 January 2006 01:41 Go to previous message
rleishman
Messages: 3728
Registered: October 2005
Location: Melbourne, Australia
Senior Member
SQL*Loader does not provide any means to "remember" a value from a previous record. If all the information you need is not on the current row, then bad luck.

I think a pre-processing (I'd use Perl) script is the most efficient solution.

However, if you are determined, you could do the following:


CREATE TABLE dummy_b1 (val varchar2(255));

CREATE PACKAGE remember_me AS
    val VARCHAR2(255);
END;
/

CREATE TRIGGER dummy_b1_t1
BEFORE INSERT ON dummy_b1
FOR EACH ROW
BEGIN
    remember_me.val = :new.dummy;
END;
/

CREATE TRIGGER h2_table_t1
BEFORE INSERT ON h2_table
FOR EACH ROW
BEGIN
    :new.val := remember_me.val;
END;
/



Then in your control file, load the second column of B1 rows into DUMMY_B1 table, and H2 rows into H2 table. As a row is loaded into B1, it will store the second column in the package where it can be retrieved as rows are loaded into H2_TABLE.

Set the load method for DUMMY_B1 to TRUNCATE to stop rows accumulating in that table. You might be able to make DUMMY_B1 a Global Temporary Table with ON COMMIT PRESERVE ROWS - worth a try.

You cannot use direct path load or parallel load.

This work-around is a bit of a mess. Personally, I would be converting the file with a Perl script.

_____________
Ross Leishman
Previous Topic: tool copy database
Next Topic: When Importing data from Toad: Error: Out Of Memory - Very Urgent
Goto Forum:
  


Current Time: Tue Jul 02 04:11:33 CDT 2024