Where Clause SQL Loader

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 Thanks

SQL*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.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • Error with When Clause SQL Loader

    I´'m trying to use WHEN clause in a control file, I'm following the documentation but it doesn't work still.
    This is my control file:
    LOAD DATA
    CHARACTERSET UTF8
    INTO TABLE DM08_CONDICIONADA
    WHEN (STATUS_DESC='A')
    APPEND
    REENABLE DISABLED_CONSTRAINTS
    FIELDS
    TERMINATED BY '|'
    "ID_COND" POSITION (1) INTEGER EXTERNAL ,
    "DESC_COND" CHAR,
    "STATUS_DESC" CHAR
    I have the follow error:
    SQL*Loader-350: Syntax error at line 26.
    Expecting "(", found keyword append.
    APPEND
    ^
    I have tried with
    WHEN STATUS_DESC='A'
    but the error is the same. Do you have any ideas why is that?? I'm working with oracle 9i.
    Greetings
    Oscar

    with:
    LOAD DATA
    CHARACTERSET UTF8
    INTO TABLE DM08_CONDICIONADA
    APPEND
    WHEN STATUS_DESC='A' --->with (STATUS_DESC='A') neither
    REENABLE DISABLED_CONSTRAINTS
    FIELDSTERMINATED BY '|'
    I have:
    SQL*Loader-350: Syntax error at line 27.
    Expecting "(", found keyword reenable.
    REENABLE DISABLED_CONSTRAINTS
    With:
    LOAD DATA
    CHARACTERSET UTF8
    INTO TABLE DM08_CONDICIONADA
    APPEND
    REENABLE DISABLED_CONSTRAINTS
    WHEN (STATUS_DESC ='A')
    i have:
    SQL*Loader-403: Referenced column STATUS_DESC not present in table DM08_CONDICIONADA.
    I´m using the documentation...
    -->full_fieldname or pos_spec-->operator--> char_string or Blanks --->
    but it doesn't tell me where the when clause goes... i'm probing too with the forum information but i don't know what happens.
    Thanks Jens

  • Define a Standalone Download Integrator with an Additional Where clause - SQL error

    Hi,
    I am trying to create a standalone integrator with an Additional Where clause. Followed the steps mentioned in the metalink note 360105.1. When I run the integrator, I get the following error message.
    Please resolve the following error to continue.
    SQL error: ORA-00936: missing expression occurred
    processing stored SQL for Content 20007:GENERAL_441_CNT.
    When I look at the log file, here is what I can see:
    10/22/14 10:50 AM AJPRequestHandler-HTTPThreadGroup-15 TRACE          BneHrSQLControl - SQL:SELECT  FROM PER_PEOPLE_V where last_name=$PARAM$.last_name
    10/22/14 10:50 AM AJPRequestHandler-HTTPThreadGroup-15 TRACE          validateSQLStatement value of sqlStatement is: SELECT  FROM PER_PEOPLE_V where last_name=:RSQLP1
    10/22/14 10:50 AM AJPRequestHandler-HTTPThreadGroup-15 DETAIL         BneHrSQLControl.validateSQLStatement() paramName: last_name
    10/22/14 10:50 AM AJPRequestHandler-HTTPThreadGroup-15 DETAIL         BneHrSQLControl.validateSQLStatement() error in SQL: java.sql.SQLSyntaxErrorException: ORA-00936: missing expression
    So, clearly, the SQL statement that is getting built internally is wrong. Ideally, I would expect the statement to be something like this:
    SELECT *  FROM PER_PEOPLE_V where last_name=$PARAM$.last_name.
    RDBMS : 11.2.0.3.0
    Oracle Applications : 12.1.3
    Any pointers towards the resolution of the issue would be of great help.
    Thanks in Advance!
    Lalitha.

    This is a duplicate post of your other question:  create trigger automatic
    DO NOT start duplicate threads for the same question.
    Locking this thread

  • Where is SQL LOADER and How i can use

    where is and where i can find and run SQL LOADER. because i want to import data from ms excel.
    regards.

    SQL*LOADER is right there on your system if you have successfully installed any of the oracle database products.
    Depending on your OS the version of the product you installed then you can invoke it from the OS command prompt. For example in windows OS and with oracle 8.0 product then issue sqllrd80 (or something like that!!). You can check what loader is actually on your system by searching for the sqlldr.*
    Also refer to oracle 8 documentation for further explanation. I hope this helps.

  • Where is SQL*Loader error message in oracle 8i documentation?

    I have error message which is SQL*Loader-522: lfiopn failed for
    file (D:\xiaw\Badfiles\faculty_info.BAD). I can't find the
    solution from oracle 8i documentation. Can someboday help me?
    Thanks
    wei

    Wei:
    They're in Chapter 24 of the Error Messages manual:
    SQL*Loader-00522 lfiopn failed for file (string)
    Cause: LFI failed to open the file.
    Action: Check for any possible operating system errors and/or
    potential memory problems.
    Hope this helps.
    Peter

  • Order in where clause - SQL statement

    Hi,
    The order of the fields in Where clause in OpenSQL statements is important to get the right index?
    Select a b c from t1
    where 
    d = p_d and
    e = p_e
    Or
    Select a b c from t1
    where 
    e = p_e and
    d = p_d
    Index:
    columns e and d.
    Thanks !

    HI,
      Both will give you the same result.. but it is always good to pass the sequence as in the table.. the performance will be good when you follow the sequece of occurance of the fields.
    Thanks
    Mahesh

  • Where is SQL*Loader?

    Hello,
    I deselected several packages during installation of Oracle 9i client. After that, I couldn't find
    the SQL*Loader (sqlldr.exe) anywhere in the directory tree. Which package should I pick to have
    the SQL*Loader installed?
    Regards,
    Fangtu

    I beleive sql*loader is part of the server tech stack, not the client tech stack.
    You should check the server cd for it.

  • Nested where clause sql??

    Hello,
    I try to do the following sql
    select a.emplid from
    tableA a
    where a.effdt =
    (select max(b.effdt) from tableA b where a.emplid = b.emplid)
    I try to use filter, it does not work, it complain that the table does not exist.
    Please advise?
    thnks

    Currently OWB does not support subqueries. It will be supported in the next major version (November 2004).
    In the meantime the (not very elegant) workaround for this is to create a view with the nested query.
    Regards:
    Igor

  • Using SAMPLE with a WHERE clause

    (Oracle 9iR2)
    I am using the SAMPLE keyword in a SELECT statement with a WHERE clause. Is the sample extracted before or after applying the WHERE clause?
    For example, if I have the statement:
    SELECT emp_id FROM employees SAMPLE(10)
    WHERE salary > 50000;
    Does the database first extract a 10% sample of all the rows and then apply the salary filter on the sample (meaning it's possible that no rows are returned even though there are rows with salary > 50000)? Or does it return a 10% sample of the rows that meet the filter condition (meaning rows will always be returned as long as there are rows with salary > 50000)?

    The sample is extracted before the where clause:
    SQL> drop table sample_test;
    Table dropped.
    SQL> create table sample_test (id number, salary number);
    Table created.
    SQL>
    SQL> begin
    2 for i in 1..99 loop
    3 insert into sample_test values (i, 100);
    4 end loop;
    5
    6 insert into sample_test values (100, 1000);
    7 end;
    8 /
    PL/SQL procedure successfully completed.
    SQL>
    SQL> commit;
    Commit complete.
    SQL>
    SQL> select * from sample_test sample(5)
    2 where salary > 100;
    no rows selected

  • SQL*Loader with Stored Procedure slow

    I have a situation where if SQL*Loader is running then stored procedures returning cursors are excruciatingly slow (about 3 minutes) if the same stored procedure is run via SQL statements it runs fine. The stored procedures also run fine if SQL*Loader is not running. Has anyone seen this before, any thoughts?
    Thanks,
    ed

    My query was:
    SELECT *
    FROM scheme.table@as400 a
    WHERE a.vlvalr = to_char(p_vlvalr)
    and a.vlvals = to_char(p_vlvals);
    Without the to_char! When I add the to_char, the problem is solved!

  • How can I invoke a sql loader from oracle form?

    I'm got a problem on invoking sql loader command from oracle form where the sql loader product has been installed in Window NT.
    Thanks for your help!

    U can use HOST procedure with NO_SCREEN option.
    this will go like
    Host('d:\orant\bin\SQLLDR80 USERID=username/password@connect CONTROL=contril_file.CTL LOG=log_file.LOG discard=discard_file.dis bad=bad_file.bad', NO_SCREEN);
    Hope this will Work
    Good Luck :-)
    Naren

  • Help on SQL Loader When Clause

    I have 2 Oracle tables of exact same structure.
    ENO NUMBER
    PARENT NUMBER
    CHILD NUMBER
    ENAME VARCHAR2 (50 Byte)
    ADDRESS VARCHAR2 (50 Byte)
    CITY VARCHAR2 (50 Byte)
    SRCFILENAME VARCHAR2 (50 Byte)
    SDATE VARCHAR2 (400 Byte)
    Current_Load VARCHAR2 (1 Byte)
    Have a data file and a loader control file which loads data in these 2 tables.
    I need to do a conditional load using a when clause.
    Condition : when PARENT=CHILD, load in table 2 else load in table 1
    My control file looks like this .
    LOAD DATA
    INFILE 'TEST_20120815.txt'
    APPEND INTO TABLE test1
    fields terminated by "|"
    trailing nullcols
    eno,
    parent,
    child,
    ename,
    address,
    city ,
    sdate "to_date(:sdate,'DD/MM/YYYY')",
    SrcFileName,
    col7 filler,
    "Current_Load" constant 'Y'
    INTO TABLE test2 when (parent=child)
    fields terminated by "|"
    trailing nullcols
    eno position(1),
    parent,
    child,
    ename,
    address,
    city ,
    sdate "to_date(:sdate,'DD/MM/YYYY')",
    SrcFileName,
    col7 filler,
    "Current_Load" constant 'Y'
    ) But this doesn't work. It works fine if I give direct value like PARENT='P'.
    Any idea as how to compare the 2 fields while doing conditional load?

    You cannot compare 2 fields with the WHEN clause in an SQL*Loader control file.
    only literal values as defined by the syntax:
    http://docs.oracle.com/cd/B19306_01/server.102/b14215/ldr_control_file.htm#i1005657
    As already suggested, you would be better to load your data using an external table where you can apply any conditions you want during your SQL query that is fetching the data.

  • SQL Loader to append data in same table but using differnet WHEN clauses

    In my data file i have a header record and a detail record identified by Record_type = 1 and 2 respectively.
    The Database table has all the columns to capture detail records but i want to capture jus one column of header record now also in my existing table. So i have added that column (DATA_DATE)in my table but how to capture that value ?
    im writing my control file using two WHEN clauses, something like -
    load data
    into table t_bdn
    append
    when RECORD_TYPE = '2'
    FIELDS TERMINATED BY "|" TRAILING NULLCOLS
    SEQUENCE_NO
    , RECORD_TYPE
    , DISTRIBUTOR_CODE
    , SUPPLIER_CODE
    , SUPPLIER_DISTRIBUTOR_CODE
    , DISTRIBUTOR_SKU
    , SUPPLIER_SKU
    when RECORD_TYPE = '1'
    FIELDS TERMINATED BY "|" TRAILING NULLCOLS
    SEQUENCE_NO FILLER
    , RECORD_TYPE FILLER
    , CREATE_DATE FILLER
    , DATA_DATE "NVL(to_date(:DATA_DATE, 'YYYY/MM/DD'),to_date('9999/12/31', 'YYYY/MM/DD'))"
    im getting error " expecting INTO and foung WHEN RECORD_TYPE = '1' "
    if i give iNTO second time it will append a new row altogether in my table but i want the same row to be updated with this DATA_DATE value coming from RECORD_TYPE =1 and header record has 4 delimited data text fields only and i am interested in fetching just the 4th column..
    KIndly suggest what to do ?

    Ravneek, I could be wrong but sqlldr is a 'load' program, that is, it inserts data. I am unaware of any ability to update existing rows as you seem to want. What you appear to want to do is more the job of a merge statement.
    I would look at writing a pro* language, a .net, or a java program to perform inserts where some or all of the newly inserted rows are also to be updated.
    From the manual: (Oracle® Database Utilities 10g Release 2 (10.2) Part Number B14215-01)
    Updating Existing Rows
    The REPLACE method is a table replacement, not a replacement of individual rows. SQL*Loader does not update existing records, even if they have null columns. To update existing rows, use the following procedure:
    1. Load your data into a work table.
    2. Use the SQL language UPDATE statement with correlated subqueries.
    3. Drop the work table.
    HTH -- Mark D Powell --

  • [Solved] Named Bind Variables at Runtime - SQL WHERE clause issue

    Hey 'all,
    I've been having this issue today with a Search page using Named Bind Variables at Runtime for the search parameters for the WHERE clause in the view objects SQL.
    I've got everything working except for a clearing method which I've created so that the user can clear the current WHERE clause from the SQL statment and set it as 1=2 (so that it doesn't do a blind query on load).
    The method can clear and set the WHERE clause to 1=2 only when there is already one there.
    Below are the methods: (located in my view object class)
    public void findInvoiceById(Number invoiceId){
        setWhereClause("invoice_id = :P_INVOICE_ID");
        defineNamedWhereClauseParam("P_INVOICE_ID",null,null);
        setNamedWhereClauseParam("P_INVOICE_ID",invoiceId);
        executeQuery();
    public void clearCriteria(){
        setWhereClause("1=2");
        removeNamedWhereClauseParam("P_INVOICE_ID");
        executeQuery();
    }The error which I get is the following - this happens when the button is pressed twice in a row, or when no query has been passed previously.
    1. JBO-29000: Unexpected exception caught: oracle.jbo.NoDefException, msg=JBO-25058: Definition P_INVOICE_ID of type Variable not found in SupplierInvoicesView1
    2. JBO-25058: Definition P_INVOICE_ID of type Variable not found in SupplierInvoicesView1
    Any help with this would be greatly appreciated!
    Cheers,

    Hi Bonnie,
    we have it working ok, but still feel that there is room for improvement in the design.
    For us the key factors are:
    Pages based on the same view object that can be queried multiple ways.
    We don't want to put design time bind variables in because it limits the use of the VO
    We don't wan't multiple VO's with different where clauses.
    The page is displaying the same table columns and fields, but the where clause must be dynamic.
    We only want to query on the search field entered (some of our tables are massive)
    TopLink named queries are really what we are after, but we don't want to forgo all the other ADF BC functionality. The only examples of ViewCriteria in the developer guide had literals in the where clause and no bind variables. The View Criteria may still be an option, but it appeared quite complex compaired to directly adding and removing bind variables at runtime.
    a couple of footnotes:
    the following methods are used to clear the runtime variables prior to reusing the VO (thanks to John Stegman for the pointer on the exception handler):
        public void clearBindVariable(String bindVariableName){
            try
                removeNamedWhereClauseParam(bindVariableName);
            catch (NoDefException e)
        public void clearBindVariables(){
            clearBindVariable("P_INVOICE_ID");
            clearBindVariable("P_INVOICE_NUM");
            clearBindVariable("P_SUPPLIER_NAME");
            clearBindVariable("P_INVOICE_DATE_FROM");
            clearBindVariable("P_INVOICE_DATE_TO");
            clearBindVariable("P_SUPPLIER_NUMBER");
        }We are using 1=1 and 1=2 in the where clause to supress blind querying. 1=2 is applied when ever we are not explicitely searching for something. We had a problem with using the refresh condition ${adfFacesContext.postback == true} which I posted about here:
    executeQuery called twice using ${adfFacesContext.postback == true}
    Would still gladly hear other ideas on a better reuse design.
    regards,
    Brenden

  • Exclude duplicate values on SQL where clause statement

    Hi!
    Are some posibilities to exclude duplicate values do not using sql aggregate functions in main select statement?
    Priview SQL statement
    SELECT * FROM
    select id,hin_id,name,code,valid_date_from,valid_date_to
    from diaries
    QRSLT
    WHERE (hin_id = (SELECT NVL(historic_id,id)FROM tutions where id=/*???*/ 59615))
    AND NVL(valid_date_to,to_date('22.12.2999','dd.mm.yyyy')) <= (SELECT NVL(valid_date_to,to_date('22.12.2999','dd.mm.yyyy'))FROM tutions where id= /*???*/ 59615)
    AND trunc(valid_date_from) >=(SELECT trunc(valid_date_from)FROM tutions where id= /*???*/ 59615)
    The result
    ID                  HIN_ID    NAME      CODE    VALID_DATE FROM                 VALID_DATE_TO    
    50512
    59564
    RE TU
    01
    07.06.2013 16:32:15
    07.06.2013 16:33:28
    50513
    59564
    TT2 
    02
    07.06.2013 16:33:23
    07.06.2013 16:33:28
    50515
    59564
    TT2 
    02
    07.06.2013 16:33:28
    07.06.2013 16:34:42
    50516
    59564
    ROD 
    03
    07.06.2013 16:34:37
    07.06.2013 16:34:42
    VALID_DATE_TO & AND VALID_DATE_FROM tutions
    07.06.2013 16:34:42
    15.07.2013 10:33:23
    In this case i got duplicate of entry TT2 id 50513  In main select statement cant use agregate functions are even posible to exclude this value from result modifying only the QLRST WHERE clause (TRUNC need to be here)
    THANKS FOR ANY TIP !
    ID.

    Hi, Ok this is working in this case
    SELECT * FROM
    select id,hin_id,name,code,valid_date_from,valid_date_to
    from diaries ahs
    QRSLT
    WHERE (hin_id = (SELECT NVL(historic_id,id)FROM aip_healthcare_tutions where id=/*???*/ 59615))
    AND NVL(valid_date_to,to_date('22.12.2999','dd.mm.yyyy')) <= (SELECT NVL(valid_date_to,to_date('22.12.2999','dd.mm.yyyy'))FROM tutions where id= /*???*/ 59615)
    AND trunc(valid_date_from) >=(SELECT trunc(valid_date_from)FROM tutions where id= /*???*/ 59615)
    AND NOT  EXISTS
    (SELECT null FROM diaries ahs WHERE  ahs.valid_date_from < QRSLT.valid_date_from
        AND QRSLT.hin_id=ahs.hin_id
        AND QRSLT.code=ahs.code);
    Result
    50512
    59564
    RE TU
    01
    07.06.2013 16:32:15
    07.06.2013 16:33:28
    50513
    59564
    TT2 
    02
    07.06.2013 16:33:23
    07.06.2013 16:33:28
    50516
    59564
    ROD 
    03
    07.06.2013 16:34:37
    07.06.2013 16:34:42
    But if the Data in tutions row  are theese(valid_date_to-null)  then NO ROWS are returning and its logical because in full result list Valid_date_from column are logical incorect
    valid_date_from                                 valid_date_to
    15.07.2013 10:33:23
    NULL
    ID                  HIN_ID    NAME      CODE    VALID_DATE FROM                 VALID_DATE_TO 
    50510
    59564
    RE TU
    01
    07.06.2013 16:33:28
    50511
    59564
    TT2 
    02
    07.06.2013 16:34:41
    50514
    59564
    ROD 
    03
    07.06.2013 16:34:41
    50520
    59564
    Params
    04
    03.07.2013 21:01:30
    50512
    59564
    RE TU
    01
    07.06.2013 16:32:15
    07.06.2013 16:33:28
    50513
    59564
    TT2 
    02
    07.06.2013 16:33:23
    07.06.2013 16:33:28
    50515
    59564
    TT2 
    02
    07.06.2013 16:33:28
    07.06.2013 16:34:42
    50516
    59564
    ROD 
    03
    07.06.2013 16:34:37
    07.06.2013 16:34:42
    Are that posible modifying where statement  if the valid_date_to in tutions are null then theese records where in diary valid_date_to is null is correct to, but need to stay previos logic
    D                  HIN_ID    NAME      CODE    VALID_DATE FROM                 VALID_DATE_TO 
    50510
    59564
    RE TU
    01
    07.06.2013 16:33:28
    null
    50511
    59564
    TT2 
    02
    07.06.2013 16:34:41
    null
    50514
    59564
    ROD 
    03
    07.06.2013 16:34:41
    null
    50520
    59564
    Params
    04
    03.07.2013 21:01:30
    null
    Thanks !
    ID.

Maybe you are looking for