HELP: SQL*LOADER AND Ref Column

Hallo,
I have already posted and I really need help and don't come further with this
I have the following problem. I have 2 tables which I created the following way:
CREATE TYPE gemark_schluessel_t AS OBJECT(
gemark_id NUMBER(8),
gemark_schl NUMBER(4),
gemark_name VARCHAR2(45)
CREATE TABLE gemark_schluessel_tab OF gemark_schluessel_t(
constraint pk_gemark PRIMARY KEY(gemark_id)
CREATE TYPE flurstueck_t AS OBJECT(
flst_id NUMBER(8),
flst_nr_zaehler NUMBER(4),
flst_nr_nenner NUMBER(4),
zusatz VARCHAR2(2),
flur_nr NUMBER(2),
gemark_schluessel REF gemark_schluessel_t,
flaeche SDO_GEOMETRY
CREATE TABLE flurstuecke_tab OF flurstueck_t(
constraint pk_flst PRIMARY KEY(flst_id),
constraint uq_flst UNIQUE(flst_nr_zaehler,flst_nr_nenner,zusatz,flur_nr),
flst_nr_zaehler NOT NULL,
flur_nr NOT NULL,
gemark_schluessel REFERENCES gemark_schluessel_tab
Now I have data in the gemark_schluessel_tab which looks like this (a sample):
1 101 Borna
2 102 Draisdorf
Now I wanna load data in my flurstuecke_tab with SQL*Loader and there I have problems with my ref column gemark_schluessel.
One data record looks like this in my file (it is without geometry)
1|97|7||1|1|
If I wanna load my data record, it does not work. The reference (the system generated OID) should be taken from gemark_schluessel_tab.
LOAD DATA
INFILE *
TRUNCATE
CONTINUEIF NEXT(1:1) = '#'
INTO TABLE FLURSTUECKE_TAB
FIELDS TERMINATED BY '|'
TRAILING NULLCOLS (
flst_id,
flst_nr_zaehler,
flst_nr_nenner,
zusatz,
flur_nr,
gemark_schluessel REF(CONSTANT 'GEMARK_SCHLUESSEL_TAB',GEMARK_ID),
gemark_id FILLER
BEGINDATA
1|97|7||1|1|
Is there a error I made?
Thanks in advance
Tig

multiple duplicate threads:
to call an oracle procedure and sql loader in an unix script
Re: Can some one help he sql loader issue.

Similar Messages

  • Help in calling sql loader and an oracle procedure in a script

    Hi Guru's
    please help me in writing an unix script which will call sql loader and also an oracle procedure..
    i wrote an script which is as follows.
    !/bin/sh
    clear
    #export ORACLE_SID='HOBS2'
    sqlldr USERID=load/ps94mfo16 CONTROL=test_nica.ctl LOG=test_nica.log
    retcode=`echo $?`
    case "$retcode" in
    0) echo "SQL*Loader execution successful" ;;
    1) echo "SQL*Loader execution exited with EX_FAIL, see logfile" ;;
    2) echo "SQL*Loader execution exited with EX_WARN, see logfile" ;;
    3) echo "SQL*Loader execution encountered a fatal error" ;;
    *) echo "unknown return code";;
    esac
    sqlplus USERID=load/ps94mfo16 << EOF
    EXEC DO_TEST_SHELL_SCRIPT
    it is loading the data in to an oracle table
    but the procedure is not executed..
    any valuable suggestion is highly appriciated..
    Cheers

    multiple duplicate threads:
    to call an oracle procedure and sql loader in an unix script
    Re: Can some one help he sql loader issue.

  • Sql*loader and nested tables

    I'm having trouble loading a nested table via sqlldr in Oracle 10g and was hoping someone could point me in the right direction. I keep getting the following error:
    SQL*Loader-403: Referenced column not present in table mynamespace.mytable
    Here's an overview of my type and table definitions:
    create type mynamespace.myinfo as object
    i_name varchar2(64),
    i_desc varchar2(255)
    create TYPE mynamespace.myinfotbl as TABLE of mynamespace.myinfo;
    create table mynamespace.mytable
    Info mynamespace.myinfotbl,
    note varchar2(255)
    NESTED TABLE Info STORE AS mytable_nested_tab;
    My control file looks like this:
    load data
    infile 'mydatafile.csv'
    insert into table mynamespace.mytable
    fields terminated by ',' optionally enclosed by '"'
    TRAILING NULLCOLS
    Info nested table count(6)
    Info column object
    i_name char(64),
    i_desc char(255)
    note
    Example mydatafile.csv would be something like:
    lvl1,des1,lvl2,des2,lvl3,des3,lvl4,des4,lvl5,des5,lvl6,des6,a test data set
    I can't figure out why sqlldr keeps rejecting this control file. I'm using 'direct=false' in my .par file.
    Any hints?

    I just noticed that my email is wrong. If you can help, plese send email to [email protected]
    thanks.

  • Using SQL*Loader and UTL_FILE to load and unload large files(i.e PDF,DOCs)

    Problem : Load PDF or similiar files( stored at operating system) into an oracle table using SQl*Loader .
    and than Unload the files back from oracle tables to prevoius format.
    I 've used SQL*LOADER .... " sqlldr " command as :
    " sqlldr scott/[email protected] control=c:\sqlldr\control.ctl log=c:\any.txt "
    Control file is written as :
    LOAD DATA
    INFILE 'c:\sqlldr\r_sqlldr.txt'
    REPLACE
    INTO table r_sqlldr
    Fields terminated by ','
    id sequence (max,1) ,
    fname char(20),
    data LOBFILE(fname) terminated by EOF )
    It loads files ( Pdf, Image and more...) that are mentioned in file r_sqlldr.txt into oracle table r_sqlldr
    Text file ( used as source ) is written as :
    c:\kalam.pdf,
    c:\CTSlogo1.bmp
    c:\any1.txt
    after this load ....i used UTL_FILE to unload data and write procedure like ...
    CREATE OR REPLACE PROCEDURE R_UTL AS
    l_file UTL_FILE.FILE_TYPE;
    l_buffer RAW(32767);
    l_amount BINARY_INTEGER ;
    l_pos INTEGER := 1;
    l_blob BLOB;
    l_blob_len INTEGER;
    BEGIN
    SELECT data
    INTO l_blob
    FROM r_sqlldr
    where id= 1;
    l_blob_len := DBMS_LOB.GETLENGTH(l_blob);
    DBMS_OUTPUT.PUT_LINE('blob length : ' || l_blob_len);
    IF (l_blob_len < 32767) THEN
    l_amount :=l_blob_len;
    ELSE
    l_amount := 32767;
    END IF;
    DBMS_LOB.OPEN(l_blob, DBMS_LOB.LOB_READONLY);
    l_file := UTL_FILE.FOPEN('DBDIR1','Kalam_out.pdf','w', 32767);
    DBMS_OUTPUT.PUT_LINE('File opened');
    WHILE l_pos < l_blob_len LOOP
    DBMS_LOB.READ (l_blob, l_amount, l_pos, l_buffer);
    DBMS_OUTPUT.PUT_LINE('Blob read');
    l_pos := l_pos + l_amount;
    UTL_FILE.PUT_RAW(l_file, l_buffer, TRUE);
    DBMS_OUTPUT.PUT_LINE('writing to file');
    UTL_FILE.FFLUSH(l_file);
    UTL_FILE.NEW_LINE(l_file);
    END LOOP;
    UTL_FILE.FFLUSH(l_file);
    UTL_FILE.FCLOSE(l_file);
    DBMS_OUTPUT.PUT_LINE('File closed');
    DBMS_LOB.CLOSE(l_blob);
    EXCEPTION
    WHEN OTHERS THEN
    IF UTL_FILE.IS_OPEN(l_file) THEN
    UTL_FILE.FCLOSE(l_file);
    END IF;
    DBMS_OUTPUT.PUT_LINE('Its working at last');
    END R_UTL;
    This loads data from r_sqlldr table (BOLBS) to files on operating system ,,,
    -> Same procedure with minor changes is used to unload other similar files like Images and text files.
    In above example : Loading : 3 files 1) Kalam.pdf 2) CTSlogo1.bmp 3) any1.txt are loaded into oracle table r_sqlldr 's 3 rows respectively.
    file names into fname column and corresponding data into data ( BLOB) column.
    Unload : And than these files are loaded back into their previous format to operating system using UTL_FILE feature of oracle.
    so PROBLEM IS : Actual capacity (size ) of these files is getting unloaded back but with quality decreased. And PDF file doesnt even view its data. means size is almot equal to source file but data are lost when i open it.....
    and for images .... imgaes are getting loaded an unloaded but with colors changed ....
    Also features ( like FFLUSH ) of Oracle 've been used but it never worked
    ANY SUGGESTIONS OR aLTERNATE SOLUTION TO LOAD AND UNLOAD PDFs through Oracle ARE REQUESTED.
    ------------------------------------------------------------------------------------------------------------------------

    Thanks Justin ...for a quick response ...
    well ... i am loading data into BLOB only and using SQL*Loader ...
    I've never used dbms_lob.loadFromFile to do the loads ...
    i 've opend a file on network and than used dbms_lob.read and
    UTL_FILE.PUT_RAW to read and write data into target file.
    actually ...my process is working fine with text files but not with PDF and IMAGES ...
    and your doubt of ..."Is the data the proper length after reading it in?" ..m not getting wat r you asking ...but ... i think regarding data length ..there is no problem... except ... source PDF length is 90.4 kb ..and Target is 90.8 kb..
    thats it...
    So Request u to add some more help ......or should i provide some more details ??

  • Import and process larger data with SQL*Loader and Java resource

    Hello,
    I have a project to import data from a text file in a schedule. A lager data, with nearly 20,000 record/1 hours.
    After that, we have to analysis the data, and export the results into a another database.
    I research about SQL*Loader and Java resource to do these task. But I have no experiment about that.
    I'm afraid of the huge data, Oracle could be slowdown or the session in Java Resource application could be timeout.
    Please tell me some advice about the solution.
    Thank you very much.

    With '?' mark i mean " How i can link this COL1 with column in csv file ? "
    Attilio

  • SQL Loader input derived column

    Hi,
    I am running SQL Loader and I have two columns in my source file I am loading along with LoadDate and the name of the source file. my loader.ctl is below:
    load data
    infile 'c:\Reports\Test20070619.txt'
    APPEND
    into table MikeTest2
    fields terminated by "," optionally enclosed by '"'
    (OrderNumber,SKU,LoadDate sysdate,SourceFile "Test20070619.txt")
    How would I add the SourceFile Field value Test20070619.txt? I can get the LoadDate to load with sysdate. Any thoughts.
    Any info would be greatly appreciated.
    Thanks,
    Mike

    (OrderNumber,
    SKU,
    LoadDate sysdate,
    SourceFile "Test20070619.txt")If I understood your question correct:
    You can do this: Create a variable for the filename and use that variable:
    in a shell program:
    cat <<EOF! > $ctl_file
    LOAD DATA
    INFILE '$in_file'
    BADFILE '$HOME/logs/$bad_file'
    DISCARDFILE '$HOME/logs/$disc_file'
    (OrderNumber,
    SKU,
    LoadDate sysdate,
    SourceFile CONSTANT "$in_filename"
    )

  • SQL*loader support database columns Of Binary Double/Float

    Does SQL*loader support database columns Of Binary Double/Float when applying Direct Path?

    Why not use Google and find out for yourself.
    The first hit on Google is this
    Go see for yourself
    Regards
    FJ

  • SQL Loader and Insert Into Performance Difference

    Hello All,
    Im in a situation to measure performance difference between SQL Loader and Insert into. Say there 10000 records in a flat file and I want to load it into a staging table.
    I know that if I use PL/SQL UTL_FILE to do this job performance will degrade(dont ask me why im going for UTL_FILE instead of SQL Loader). But I dont know how much. Can anybody tell me the performance difference in % (like 20% will decrease) in case of 10000 records.
    Thanks,
    Kannan.

    Kannan B wrote:
    Do not confuse the topic, as I told im not going to use External tables. This post is to speak the performance difference between SQL Loader and Simple Insert Statement.I don't think people are confusing the topic.
    External tables are a superior means of reading a file as it doesn't require any command line calls or external control files to be set up. All that is needed is a single external table definition created in a similar way to creating any other table (just with the additional external table information obviously). It also eliminates the need to have a 'staging' table on the database to load the data into as the data can just be queried as needed directly from the file, and if the file changes, so does the data seen through the external table automatically without the need to re-run any SQL*Loader process again.
    Who told you not to use External Tables? Do they know what they are talking about? Can they give a valid reason why external tables are not to be used?
    IMO, if you're considering SQL*Loader, you should be considering External tables as a better alternative.

  • 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.
    Thanx

    External 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

  • Is there any difference in Oracle 9i SQL Loader and Oracle 10g SQL Loader

    Hi
    Can anyone tell me whether is there any difference in Oracle 9i SQL Loader and Oracle 10g SQL Loader?
    I am upgrading the 9i db to 10g and wanted to run the 9i SQL Loader control files on upgraded 10g db. So please let me know is there any difference which I need to consider any modifications in the control files..
    Thank you in advance
    Adi

    answered

  • SQL Loader Constraints with Column Objects and Nested Tables

    I am working on loading a Table that (god forbid) contains columns, column objects, and nested tables (which contains several depth of column objects). My question is does SQL Loader have a hidding undocumented feature where it states how the column objects must be grouped in refereneced to the nested tables within the loader file? I can load the various column objects, and nested tables fine right now, however, I am loading them all in strange and insane order. Can anyone answer this question? Thanks.
    Peter

    I just noticed that my email is wrong. If you can help, plese send email to [email protected]
    thanks.

  • SQL Loader and control file

    I know I've done this before but, I don't use SQL Loader often and I'm having issues getting a file to load.
    The table has 6 columns in it - one of which is a timestamp.
    I was having issues loading it initially with date format issues. I ruled out any issues with the timestamp format by simply loading a dummy table with some timestamp based data and had no issue.
    So - I think the issue is around the fact that the table I'm loading's first column being a value I'm attempting to default with a sequence when loading and - that I'm screwing up something there.
    Table is as such:
    CREATE TABLE ACS_IPS
        (seq_ips NUMBER,
        col2   VARCHAR2(100),
        col3  VARCHAR2(100),
        col4    VARCHAR2(100),
        col5 TIMESTAMP,
        col6    VARCHAR2(100),
        col7    VARCHAR2(100),
        col8 DATE  DEFAULT SYSDATE NOT NULL,
        col9 VARCHAR2(30) DEFAULT USER);The control file is:
    load data
    truncate
    into table acs_ips
    fields terminated by ","
    trailing nullcols
        seq_ips "seq_ips.nextval",
        col2,
        col3,
        col4,
        col5 TIMESTAMP "YYYY-MM-DD HH24:MI:SS.FF9",
        col6,
        col7
        )The sequence column isn't in the file being loaded... and - there are additional columns that are defaulted on the table that aren't in the control file.
    Any help is appreciated... The error I'm getting is:
    Rejected - Error on table CAMS.ACS_IPS, column ACTION_START.
    ORA-01841: (full) year must be between -4713 and +9999, and not be 0

    Yeah - not sure that clears it up...
    The sequence in my table is the first column - and - I think that's the problem... the sequence is being loaded as the first column in the control file but - it's not in the file being loaded so - it's skewing (again - I think??) the data being read in - which is why I'm getting the timestamp issues on the one column (it's actually reading the next column in the file vs. the actual timestamp one).
    If that's the issue - I'm not sure how to avoid it without restructuring the table to stick the sequence physically at the end. I'm certain that's not necessary and - I'm overlooking something that's otherwise simple but evading me.

  • SQL Loader and INSERT Trigger

    I have problem and your help to solve it would be very much appreciated.
    I am uploading a text file with SQL Loader into a table. Since I used APPEND option in the Loader, I don't want records to be duplicated. So, I wrote a "BEFORE INSERT .. FOR EACH ROW" trigger to check whether that row already exists or not.
    For example, let us consider a table TEST as follows.
    Fld1     NUMBER(2);
    Fld2     VARCHAR2(10);
    Fld3     VARCHAR2(10);
    I have a trigger on this table.
    CREATE OR REPLACE TRIGGER Trg_Bef_Insert_Test
    BEFORE INSERT ON Test FOR EACH ROW
    DECLARE
    vCount NUMBER(2);
    DuplicateRow EXCEPTION;
    BEGIN
    SELECT Count(*) INTO vCount FROM Test
         WHERE fld1 || fld2 || fld3 = :new.fld1 || :new.fld2 || :new.fld3;
    IF vCount > 0 THEN
         RAISE DuplicateRow;
    END IF;
    EXCEPTION
    WHEN DuplicateRow THEN
         Raise_Application_Error (-20001,'Record already exists');
    WHEN OTHERS THEN
         DBMS_OUTPUT.PUT_LINE('ERROR : ' || SQLCODE || '; ' || SUBSTR(SQLERRM, 1, 150));
    END;
    Please refer to the following SQL statements which I executed in the SQL Plus.
    SQL> insert into test values (1,'one','first');
    1 row created.
    SQL> insert into test values (1,'one','first');
    insert into test values (1,'one','first')
    ERROR at line 1:
    ORA-20001: Record already exists
    ORA-06512: at "CAMELLIA.TRG_TEST", line 13
    ORA-04088: error during execution of trigger 'CAMELLIA.TRG_TEST'
    Would anyone tell me why do errors -6512 and -4088 occur ?
    Also, if you have any other suggestion to handle this situation, please let me know.
    By the way, I am using Oracle 8.1.7.
    Thank you.

    There are a few things wrong here, but you should really use a unique constraint for this.
    SQL> create table t (a number, b number, c number,
      2      constraint uk unique (a, b, c));
    Table created.Here's an example data file with 12 records three of which are duplicates.
    1,2,3
    3,4,5
    6,7,8
    3,2,1
    5,5,5
    3,4,5
    3,2,1
    1,1,1
    2,2,2
    6,7,8
    8,8,8
    9,9,9And a control file
    load data
    infile 'in.dat'
    append
    into table t
    fields terminated by ',' optionally enclosed by '"'
    (a, b, c)Running it with sql loader, inserts the nine records, outputs the three duplicates to a .bad file and logs all the errors in the .log file. No need for triggers or any code.
    $ sqlldr control=in.ctl
    Username:xxx
    Password:
    SQL*Loader: Release 9.2.0.1.0 - Production on Mon Apr 21 23:16:44 2003
    Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.
    Commit point reached - logical record count 12
    $ cat in.bad
    3,4,5
    3,2,1
    6,7,8
    SQL> select * from t;
             A          B          C
             1          2          3
             3          4          5
             6          7          8
             3          2          1
             5          5          5
             1          1          1
             2          2          2
             8          8          8
             9          9          9
    9 rows selected.

  • Sql loader and bulk data

    hi,
    I want to insert 100,000 records daily in a table for the first month and then in next month these records are going to be replaced by new updated records.
    there might be few addition and deletion in the previous records also.
    actually its consumer data so there might be few consumer who have withdrawn the utility and there will be some more consumer added in the database.
    but almost 99% of the previous month data have to be updated/replaced with the fresh month data.
    For instance, what i have in my mind is that i will use sql loader to load data for the first month and then i will delete the previous data using sqlPlus and load the fresh month data using sql loader again.
    1. Is this ok ? or there is some better solution to this.
    2. I have heard of external files, are they feasible in my scenario?
    3. I have planned that i will make scripts for sqlPlus and Loader and use them in batch files. (OS windows 2003 server, Oracle 9i database). is there some better choice to make all the procedure automatic?
    looking for your suggestions
    nadeem ameer

    I would suggest u use External tables since its more flexible then
    sqlloader & is a better option.
    For using external tables
    1)u will have to create a directory first
    2)Generally creation od directory is done by sys,hence after creating the directory
    privileges read & write to be provided to user .
    3)Creation of external tables.
    4) Now use the table as a normal table to insert ,update delete in
    ur table.
    U can get more information from
    http://www.oracle-base.com/articles/9i/SQLNewFeatures9i.php#ExternalTables
    Create Directory <directory_name> as <Directory path where file be present>
    Grant read,write on directory <directory_name> to <username>
    CREATE TABLE <table_name>
    (<column names>)
    ORGANIZATION EXTERNAL
    TYPE ORACLE_LOADER
    DEFAULT DIRECTORY ,directory_name>
    ACCESS PARAMETERS
    RECORDS DELIMITED BY NEWLINE
    FIELDS TERMINATED BY ','
    LOCATION (<filename>)
    PARALLEL 5
    REJECT LIMIT 200;
    Hope this helps.

  • SQL*Loader and "Variable length field was truncated"

    Hi,
    I'm experiencing this problem using SQL*Loader: Release 8.1.7.0.0
    Here is my control file (it's actually split into separate control and data files, but the result is the same)
    LOAD DATA
    INFILE *
    APPEND INTO TABLE test
    FIELDS TERMINATED BY ','
    OPTIONALLY ENCLOSED BY '"'
    first_id,
    second_id,
    third_id,
    language_code,
    display_text VARCHAR(2000)
    begindata
    2,1,1,"eng","Type of Investment Account"
    The TEST table is defined as:
    Name Null? Type
    FIRST_ID NOT NULL NUMBER(4)
    SECOND_ID NOT NULL NUMBER(4)
    THIRD_ID NOT NULL NUMBER(4)
    LANGUAGE_CODE NOT NULL CHAR(3)
    DISPLAY_TEXT VARCHAR2(2000)
    QUESTION_BLOB BLOB
    The log file displays:
    Record 1: Warning on table "USER"."TEST", column DISPLAY_TEXT
    Variable length field was truncated.
    And the results of the insert are:
    FIRST_ID SECOND_ID THIRD_ID LANGUAGE_CODE DISPLAY_TEXT
    2 1 1 eng ype of Investment Account"
    The language_code field is imported correctly, but display_text keeps the closing delimiter, and loses the first character of the string. In other words, it is interpreting the enclosing double quote and/or the delimiter, and truncating the first two characters.
    I've also tried the following:
    LOAD DATA
    INFILE *
    APPEND INTO TABLE test
    FIELDS TERMINATED BY '|'
    first_id,
    second_id,
    third_id,
    language_code,
    display_text VARCHAR(2000)
    begindata
    2|1|1|eng|Type of Investment Account
    In this case, display_text is imported as:
    pe of Investment Account
    In the log file, I get this table which seems odd as well - why is the display_text column shown as having length 2002 when I explicitly set it to 2000?
    Column Name Position Len Term Encl Datatype
    FIRST_ID FIRST * | O(") CHARACTER
    SECOND_ID NEXT * | O(") CHARACTER
    THIRD_ID NEXT * | O(") CHARACTER
    LANGUAGE_CODE NEXT 3 | O(") CHARACTER
    DISPLAY_TEXT NEXT 2002 VARCHAR
    Am I missing something totally obvious in my control and data files? I've played with various combinations of delimiters (commas vs '|'), trailing nullcols, optional enclosed etc.
    Any help would be greatly appreciated!

    Use CHAR instead aof VARCHAR
    LOAD DATA
    INFILE *
    APPEND INTO TABLE test
    FIELDS TERMINATED BY ','
    OPTIONALLY ENCLOSED BY '"'
      first_id,
      second_id,
      third_id,
      language_code,
      display_text    CHAR(2000)
    )From the docu:
    A VARCHAR field is a length-value datatype.
    It consists of a binary length subfield followed by a character string of the specified length.
    http://download-west.oracle.com/docs/cd/A87860_01/doc/server.817/a76955/ch05.htm#20324

Maybe you are looking for