Using User function in SQL*Loader

Hi, I have created the following control file. I am using DIRECT path insert. I am using a function to retrieve the column system_date. However, when I am running sql*loader, the fields system_date and load_date are loaded with null value.
OPTIONS (ERRORS=999999999, DIRECT=TRUE, ROWS=100000, SKIP=1)
LOAD DATA
INFILE 'Z:\xx.csv'
APPEND
PRESERVE BLANKS
INTO TABLE TB_RAW_DATA
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
REFERENCE_NUMBER,     
SYSTEM_DATE "pkg_ken_utility.Fn_ken_get_param_value('SYSTEM_DATE','SYSTEM_DATE')",
LOAD_DATE "SYSDATE"
)

No,
You can not call PL/SQL functions in DIRECT PATH mode, also this is documented, so you should not need to ask.
Sybrand Bakker
Senior Oracle DBA

Similar Messages

  • How to use nvl() function in SQL Loader

    I am trying to use nvl() funtion in my SQL Loader control file and I keep geting errors. Would someone please tell me where I can find the syntax reference to this?
    Thanks a lot!

    I just answered a similar question like this last Thursday.
    SQL*LOADER how to load blanks when data is null

  • Problem using extract function (PL/SQL) with "&#34"

    Hi,
    When I use extract function (PL/SQL), it does not transform well "&#34". Insted of returning ' " ' , it returns ' &quot '.
    I know this works changing the code replacing xml.extract for SELECT extractvalue(xml,'//A/text()') into v from dual;
    But Is there another way to do this using PL/SQL? any patch, option..?
    Regards

    Had to use my website to demonstrate the code...
    As said, whatever I try here the code gets automatically converted...
    See for answer on your question: http://www.liberidu.com/blog/?p=635

  • 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"
    )

  • Use of WHEN in SQL Loader Control File

    Does anyone know of a way, using the CTL file below, to NOT LOAD (i.e. discard) any record where field G is null -OR- substr(G,1,3)='CON'+ (the first 3 characters of field G are "CON")?
    The WHEN clause seems very limited in what it can test and all my attempts to use a compound condition, much less the SUBSTR function, have failed. The documentation indicates that only very simple conditions can be specified.
    (Oracle 10g, Unix)
    Thanks
    LOAD DATA
    TRUNCATE
    INTO TABLE TEST_TABLE
    WHEN (G <> '')
    FIELDS TERMINATED BY "^"
    TRAILING NULLCOLS
    A ,
    B FILLER,
    C FILLER,
    D FILLER,
    E FILLER,
    F FILLER,
    G "LTRIM(:G,'0')",
    H FILLER,
    I FILLER,
    J FILLER,
    K SYSDATE,
    L CONSTANT "SQLLDR"
    )

    Hello MTM.
    The WHEN clause in SQL*Loader, despite what you might read, doesn't seem to evaluate the value of the column you specify after SQL clauses are processed. Therefore, the only way you can guarantee to NOT LOAD a record is by using a function to raise an application error when the column data meets your criteria. You'll need to do some basic comparisons between bad data and discarded data in the bad data file to isolate these.
    You can still discard the null data using (replace ne with greater and less than)WHEN (g ne '')Hope this helps,
    Luke
    Please mark the answer as helpful or answered if it is so. If not, provide additional details.
    Always try to provide create table and insert table statements to help the forum members help you better.

  • Using constant values in SQL Loader control file

    Hi,
    I have a requirement where I need to migrate the data of 6 tables from MS Access into Oracle data base. I have written SQL Loader scripts so that I can create CSV files based on MS Access data and then migrate into Oracle. But in Oracle tables we have 4 common columns like Create_By, Created_Date,Updated_By and Update_Date, and those fields should be taken care by system. So, basically system should update login user ID and sysdate values in respective columns. My question here is, I do not have above mentioned common columns in MS Access tables. So, can I hard code those values in control file by saying
    Created_By CONSTANT user,
    Create_Date CONSTANT TO_CHAR(SYSDATE,'MM/DD/YYYY HH24:MI:SS'),
    Updated_By CONSTANT user,
    Updated_Date CONSTANT TO_CHAR(SYSDATE,'MM/DD/YYYY HH24:MI:SS')
    Please let me know your valuable suggestions.

    You do it without it constant
    --sample data file
    1,2,,
    3,4,,
    LOAD DATA
    INFILE 'D:\d.csv'
    INTO TABLE ABC
    FIELDS TERMINATED BY ","
    ( A,
      B,
      C sysdate,
      D "USER"
    )Edited by: J99 on Jul 23, 2009 12:14 PM
    OR use to avoid extra ',' in datafile.
    --sample data file
    1,2
    3,4
    LOAD DATA
    INFILE 'D:\d.csv'
    INTO TABLE ABC
    FIELDS TERMINATED BY "," TRAILING NULLCOLS
    ( A,
      B,
      C sysdate,
      D "USER"
    )

  • Trim Function in SQL Loader

    Oracle version 10g
    I have control file like below and would like to know is there a better way to declare trim function at the top level instead of specifying at field level. I want to remove leading or trailing spaces for the field.
    LOAD DATA
    INFILE *
    TRUNCATE
    INTO TABLE TMPTUPS_POD_DLY
    ORD_NO POSITION(1:15) "TRIM(:ORD_NO)",
    CUST_PO_NO POSITION(16:37) "TRIM(:CUST_PO_NO)",
    SHP_NAME POSITION(38:72) "TRIM(:SHP_NAME)",
    SHP_ADDR POSITION(73:102) "TRIM(:SHP_ADDR)",
    SHP_CTY POSITION(103:132) "TRIM(:SHP_CTY)",
    SHP_ST POSITION(133:134),
    SHP_ZIP POSITION(135:144),
    SHP_DT POSITION(145:154) DATE "YYYY-MM-DD",
    TRCKNG_NO POSITION(155:184),
    NOU POSITION(185:192) INTEGER EXTERNAL,
    SHP_WGT POSITION(193:204) "TO_NUMBER(:SHP_WGT,'999999999999')/100",
    POD_NAME POSITION(205:234) "TRIM(:POD_NAME)",
    POD_DT POSITION(235:244) DATE "YYYY-MM-DD",
    POD_TIME POSITION(245:252) DATE "HH:MI:SS",
    AIR_BLL_PC POSITION(253:260) INTEGER EXTERNAL,
    POD_STS_CD POSITION(261:262)
    )

    user13143312 wrote:
    That's right. if I have 5 to 10 varchar2 columns I have to mention at the field level. Just like PRESERVE BLANKS or TRAILING NULLCOLS at the top level, I thought is there a way to trim all fields at the top level. I will continue to use at the field level. Thanks!http://download.oracle.com/docs/cd/B19306_01/server.102/b14215/ldr_field_list.htm#i1007768
    If you specify them as varchar2's the trailing blanks will be trimmed.
    Also ... to remove the leading blanks.
    Optional Enclosure Delimiters
    Leading whitespace is also removed from a field when optional enclosure delimiters are specified but not present.
    Whenever optional enclosure delimiters are specified, SQL*Loader scans forward, looking for the first enclosure delimiter. If an enclosure delimiter is not found, SQL*Loader skips over whitespace, eliminating it from the field. The first nonwhitespace character signals the start of the field. This situation is shown in Field 2 in Figure 9-6. (In Field 1 the whitespace is included because SQL*Loader found enclosure delimiters for the field.)
    "

  • Using cursor function in sql statement

    hi all
    can anyone plss explain why and when we will use cursor function in a sql statement like this and what is the difference while executing this sql statement with cursor function in comparison of a simple sql statement----
    select
    department_name,
    cursor (
    select last_name
    from employees e
    where e.department_id = d.department_id
    order by last_name
    ) the_employees
    from departments d
    thnx in advance

    RTFM
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/sqloperations.htm#sthref1452
    Cheers
    Sarma.

  • Using oracle sequence in SQL Loader

    I'm using oracle sequence in control file of sql loader to load data from .csv file.
    Controlfile:
    LOAD DATA APPEND
    INTO TABLE PHONE_LIST
    FIELDS TERMINATED BY "," TRAILING NULLCOLS
    PHONE_LIST_ID "seqId.NEXTVAL",
    COUNTRY_CODE CHAR,
    CITY_CODE CHAR,
    BEGIN_RANGE CHAR,
    END_RANGE CHAR ,
    BLOCKED_FREE_FLAG CHAR
    Datafile:
    1516,8,9,9,B
    1517,1,1,2,B
    1518,8,9,9,B
    1519,8,9,9,B
    1520,8,9,9,B
    1521,8,9,9,B
    1) As first column uses oracle sequence, we have not defined that in datafile.
    This gives me error "Can not insert NULL value for last column"
    Is it mandatory to specify first column in datafile, even though we are using sequence?
    2) Another table is referencing PHONE_LIST_ID column (the one for which we using sequence) of this table as a foreign key.
    So is it possible to insert this column values in other table simultaneously? Sequence no. should be same as it is in first table...
    Kindly reply this on urgent basis....

    use BEFORE INSERT trigger
    with
    select your_seq.nextval into :new.id from dual;

  • Index is unusable after using Direct path of SQL Loader

    When using the Direct path of SQL Loader to load records from a comma(,) seperated file into a table, the index which I specify the records are sorted in becomes unusable. In the log file created by SQL Loader the error: "ORA-01409: NOSORT option may not be used; rows are not in ascending order" occurs. I am pre sorting the data in the order of the index, the index is a multi column index. The index and table prior to initiating SQL Loader are not empty and contain existing records.
    Can anybody suggest a reason as to why this is happening even thought I am pre sorting the data in ascending order as per the index?
    Brad.

    Thanks for reply Gerald!
    After further investigation I kind of answered my own question and found that the data I was loading was not in the order that Oracle was expecting. The problem stems from how the UNIX command SORT works compared to how data is ordered by in Oracle by the ORDER BY statement. I was using UNIX's SORT command to pre sort my data before loading it directly into Oracle.
    UNIX's SORT seems to order Null's before anything else in ascending order, where as Oracle's ORDER BY order's Null values last for ascending order!
    I got around this by putting in my pre-sorted data the highest printing ASCII character when ever a field was Null. The highest printing ASCII character is 'tilde' (~). As UNIX's SORT uses the ASCII collating sequence to determine the sort order the post-sorted data was sorted as per Oracle expected. And to not actually load up "~" into my Oracle table I just specified in the SQL*Loader control file for these fields, NULLIF (field_name = "~").

  • Regardin handling exception in a function, while using that function in sql

    Hi gurus,
    I have a question regarding logging exceptions while using functions.
    I wrote a separate package to handle errors, where i have a procedure.
    In this proc i'm logging my error into a table and then raise the error to the front end.
    Ex:
    proc_log_and_raise    -- this proc... inserts my error into a table and then raisenow i included this error procedure in all functions and procedures.
    consider an example with a sample procedure and function.
    function func_1(( v_var   varchar2) return varchar2 is
    begin
         select   column2
         from     table2
        where col1 = v_var;
    exception
        when others then
             proc_log_and_raise;
    end;  
    procedure proc_1( v_var   varchar2) is
    begin
        select   func_1(v_var)  -- error occurs here..
        from     table_a
        where   col1 = v_var;
    exception
        when others then
             proc_log_and_raise;
    end;    now i do
    exec  proc_1( v_var );but now my problem is, when an error occurs in func_1, i'm getting an error with DML operation ( as we are inserting into error table)
    ORA-14551: cannot perform a DML operation inside a query.
    so what i want to do is, log both function and procedure where error occured.
    So is there any other better way, we can write our exception handling, so that i can log error and use function in a select statement.
    thank you.

    I changed my procedure a little, to make it simple.
    FUNCTION        PKG_WEEKLY.FUNC_1
                RETURN NUMBER IS 
                exc exception;
    BEGIN                         
                raise exc;
                RETURN           v_provr_rcoupt;
    EXCEPTION
                when exc then
                            PKG.PKG_ERROR.USP_LOG_AND_RAISE(
                                        'batch_1',
                                        'func_1',
                                        SQLCODE,
                                        DBMS_UTILITY.FORMAT_ERROR_STACK || DBMS_UTILITY.FORMAT_ERROR_BACKTRACE()); 
    END FUNC_1;     
    PROCEDURE    PKG_WEEKLY.PROC_1(
                cur_details                                OUT      sys_refcursor) IS
    BEGIN
                OPEN cur_details FOR
                SELECT            NVL(PKG.PKG_WEEKLY.FUNC_1,0))    FROM DUAL;
    EXCEPTION
                WHEN OTHERS THEN
                            REPORT_APP_PKG.PKG_REPORT_ERROR.USP_LOG_AND_RAISE(
                                        'batch_1',
                                        'PROC_1',
                                        SQLCODE,
                                        DBMS_UTILITY.FORMAT_ERROR_STACK || DBMS_UTILITY.FORMAT_ERROR_BACKTRACE());  
    END PROC_1; Now i execute it.
    exec PKG_WEEKLY.PROC_1(:cursor); Error logged into the table:
    242 batch_1 func_1 ORA-06510: PL/SQL: unhandled user-defined exception
    ORA-06512: at "REPORT_APP_PKG.PKG_REPORT_WEEKLY_CAO", line 230
    04/14/2009 16:09:25
    ERRORS displayed to the front end:
    ORA-20156: ORA-06510: PL/SQL: unhandled user-defined exception
    ORA-06512: at "PKG.PKG_WEEKLY", line 230
    ORA-06512: at "PKG.PKG_ERROR", line 48
    ORA-06512: at "PKG.PKG_ERROR", line 226
    ORA-06512: at "PKG.PKG_WEEKLY", line 261
    thank you

  • How to use evaluate function for sql server function

    Hi Team,
    We have imported a column(date dtat type) from SQL server cube . By default it imported as varchar,. We have three option in physical layer for this column(Varchar,Intiger,unknown)
    So we want to convert this column into date.can we use evaluate or there is any option to do that.?

    Hi,
    I am not sure your requirement. But how pass evaluate function obiee?
    syntax:- EVAULATE('your db function(%1,%2)', parameter list)
    here %1 and %2 are the no.of parameters (columns or may constant values) to be passed for the db-function
    if you have 3 parameters then you need to use %3 also.. means the columns to be passed.
    following exapmples are for ORACLE db,
    ex1: EVALUATE('upper(%1)', 'satya ranki reddy') gives the result as -> SATYA RANKI REDDY
    ex2: EVALUATE('upper(%1)', 'Markets.Region') here Markets.Region is column.
    you also can call the user-defined functions through evaulate
    EVALUATE('functioname(%1,%2), column1, column2)
    the above function has 2 parameters to be inputted
    Hope this help's
    Thanks
    Satya

  • Using DECODE Function in SQL

    I need to know if there is any way to use a range of values from
    database and decode to certain text. I am able to do with one
    value.
    for example:
    DECODE(column_name,'216767111','Unlimited',column_name)
    above argument works with one value only. How about a range,
    ex: 216767000 to 216767111. I need to use only SQL. No PL/SQL.
    Kinldly need some body's help
    Thanks
    Munis

    Which version of the database? If it's 8i+ then you can use
    the CASE function
    for example:
    (CASE WHEN column_name between 216767000 and 216767111
    THEN 'Unlimited' ELSE column_name END)
    This won't work in PL/SQL because they're introducing a CASE
    statement does soemthing different.
    rgds, APCHello Andrew
    Thank you for response. I am using 8i. 8.1.6. However using
    CASE, I get inconsistent data type, ORA-00932: inconsistent
    datatypes. I able to work it out with other response using
    DECODE(sign(. Do you have any idea why i am getting this error.
    If time permits, let me know

  • Using XML functions in SQL Developer

    Hi,
    I'm using OSD 1.5.3 on a WinXP machine. I love OSD and use it every day! But I think i found a little bug. When you use some Oracle XML functions like (XMLELEMENTS and XMLAGG) in your query (these functions return CLOB values) it hangs OSD.
    For Example:
    SELECT XMLELEMENT("Relation",
    XMLELEMENT("Name", 'Dennis'),
    XMLELEMENT("DateOfBirth", '09/28/1975')
    ) as Relation
    FROM DUAL;
    Are there some parameters I can set to prevent this, or is this a bug?
    Kind Regards,
    D.

    Your query works fine for me from SQL Dev 1.5.3 (JDK 1.6.0_06), using either a JDBC or TNS connection (Oracle Client 9.2) to a 10.2.0.3 DB. Another thing which I have no idea if it is relevant (someone else may be able to say) is the following line from Help > About > Properties:
    oracle.xdkjava.compatibility.version     9.0.4
    Given that it works fine over TNS connections from SQL*Plus and PL/SQL Developer, I would assume that it is something related to your SQL Developer setup, unless you are using a different version of the Oracle client for these tools.
    theFurryOne

  • Using Bulk insert or SQL Loader in VB6

    Hi,
    I am quite new to the Oracle world and also forums. But I am looking for some directions in how i get a dataset of 10000 records into a table the quickest way. I have the recordset in an ADO Recordset (or a textfile if that is easier) and I want to insert them in an empty Oracle table. The problem is - I don't know how to.
    Situation
    The Oracle DB is on another computer I have nothing special installed on the computer running the VB6 application.
    Can anyone please provide code example or guidelines...
    Regards,
    Christian

    This may not be "bulk insert" by your definition, but it can transfer data as you want.
    A simple VB code for demo purpose:
    Dim con As New ADODB.Connection
    Dim con2 As New ADODB.Connection
    Dim rst As New ADODB.Recordset
    Dim rst2 As New ADODB.Recordset
    Dim rst3 As New ADODB.Recordset
    con.ConnectionString = "Provider=OraOLEDB.Oracle.1;User ID=scott;Password=tiger;Data Source=db_one;"
    con.Open
    rst.Open "select * from dept", con, adOpenDynamic, adLockOptimistic
    'save to a file using ADTG format. You may choose other format.
    rst.Save "c:\myfile.txt", adPersistADTG
    'dept2 is an empty table with the same table definition as dept. You can create it using SQL*Plus.
    'add rows by reading from the saved file.
    con2.ConnectionString = "Provider=OraOLEDB.Oracle.1;User ID=xyz;Password=xyz;Data Source=db_two;"
    con2.Open
    'open the saved file
    rst2.Open "c:\myfile.txt"
    'rst3 is an empty recordset because dept2 is empty at this time.
    rst3.Open "select * from dept2", con2, adOpenDynamic, adLockOptimistic
    'adding rows into dept2.
    Do Until rst2.EOF
    rst3.AddNew Array("deptno", "dname", "loc"), Array(rst2.Fields("deptno"), rst2.Fields("dname"), rst2.Fields("loc"))
    rst2.MoveNext
    Loop
    rst.Close
    rst2.Close
    rst3.Close
    con.Close
    con2.Close
    Sinclair

Maybe you are looking for

  • How can i use one dtd inside another dtd

    Hello friends, I have read some where that one DTD can be imported into another DTD but idont remember how to do it. My question is suppose we have a DTD say xyz.dtd and i am writing a new DTD say abc.dtd, and lets assume that in abc.dtd i have to de

  • Help needed creating export file from a file layout with Application Engine

    The following is what I would like to do: - Read a record from a PS view - Manipulate the data as needed - Write the fields out to a file as defined by a File Layout - Repeat until no more records are found I have created the PeopleSoft Application E

  • User Datastore for multiple tables and columns!

    Hi, I hop so much, someone can help me. I've made a user datastore to index multiple columns of multiple tables. Now, the Documentation of Oracle explains the idexing of one table. I have multiple tables, which have all, the columns descr and tagnr.

  • How do I Re enabled the Buttons in MainMovie.swf from a Button within SecondMovie.swf???

    I have the following situation MainMove.swf is doing a loadmovie of SecondMovie.swf The Button that loads SecondMovie.swf also disables other buttons in MainMovie.swf on (release) {     _root.intro_btn.enabled = false;     loadMovieNum("SecondMovie.s

  • HR portal error

    Hi Experts,   I have a user raise a problem when he tried to use our HR portal. He can log in HR portal successfully, but when he logged in the portal and enter "Performance Appraisal" page, error messages are displayed on the screen as below: Portal