Constant variable in control file - sqlldr

Hi all,
Is there a way to create a dynamic constant variable within the control file?
I'm trying to load from a csv file but need just 2 values from the 1st row, as a constant for the inserts for the rest of the rows.
How/can I use a variable and assign this value to it and use that variable inside the control file?
For example: (first character: 1=header, 2=content)
.csv file:
1,constant1,constant2
2,data11,data12
2,data21,data22
2,data31,data32
2,data41,data42
table:
col1 col2 col3 col4
data11 data12 constant1 constant2
data21 data22 constant1 constant2
data31 data32 constant1 constant2
data41 data42 constant1 constant2
Thank you soo much for your help
Edited by: user9215527 on Nov 15, 2011 8:08 PM
Edited by: user9215527 on Nov 15, 2011 8:11 PM
Edited by: user9215527 on Nov 17, 2011 9:48 AM

I am thinking about the following:
1. Load the data into 2 separate tables (header and content)
2. Update the content with the constant value from header.
Question:
Is there any other better way that I can do? Like can those 2 steps be done in a single control file?
Pls help.
====================================================
Step 1:
load data
infile 'test.txt'
append
into table zz_test_hdr
when (1:1) = '1'
( constant_1 POSITION(2:12) ,
constant_2 POSITION(13:23))
into table zz_test
when (1:1) = '2'
( col_1 POSITION(2:11),
col_2 POSITION(12:22))
Step 2:
update zz_test
set (col_3, col_4) = (select constant_1,constant_2 from zz_test_hdr);
=============================================

Similar Messages

  • How to use local variables in control files for loading data

    i want to count the number of records which have odd number like...
    Data in data.txt
    1 a
    2 b
    3 c
    So my count = 2, i will write this to another file.
    Plz help me how to achieve this

    If you want to extract some rows from a file and write them to another one, why do you need Oracle? What is your requirement?
    Or are you asking out of curiosity how can this be done in Oracle?
    You can create an external table for this input file, select the rows you want from it and write them to another file using utl_file.
    External tables: http://download.oracle.com/docs/cd/B19306_01/server.102/b14215/et_concepts.htm#SUTIL011
    UTL_FILE: http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/u_file.htm#sthref14095

  • Configuring unicode charcterset for fixed length control file

    Hi all,
    we are setting our control file to support any language characters while data loading, we all set with our database configuration , need to configure our control file which is fixed length, we are using CHARACTERSET UTF8 and and also tried with CHARACTERSET AL32UTF16, its working fine for variable length control file but for fixed length the foriegn charecers like latin-I,greek, danish charactrers are taking more byte and affecting to next position data. and our data file is in UTF8 (not in regular ANSI formatt).
    please advise
    here is our control file example:
    options (errors=999,SKIP=0)
    Load DATA
    CHARACTERSET UTF8
    append
    INTO TABLE TABLE_NAME
    TRAILING NULLCOLS
    field_name1 position(1:30) "trim(:fiels_name1)",
    field_name2 position(247:306) "trim(:field_name2)",
    )

    I think you should move thread to: {forum:id=732}.

  • Define variable in SQL Loader Control File

    Hi,
    I have an input file where the first line is the header record, followed by the detail records. For the processing, I do not need to store the fields of the header record but I need a date field from this header record and store in as part of the detail record in an oracle record row.
    Is it possible to define a variable within the sql loader control file to store the value that I need in memory then use it when I do the sql insert by the sql loader?
    Thanks for any advice.

    Not sure that you can. But if your on unix/linux/mac its easy enough to write a shell script to populates the variables in a template file that you can then use as the ctl file. The perl template toolkit could be an option for that as well

  • How can I hide constant variable value in class file?

    hi,everybody.
    I am having a problem with constant variable which define connectted with database(URL,username,password).
    when I used UltraEdit to open class file, I can see constant variable value.
    Thanks!

    OK, let's see. Firstly, if I may correct your terminology, the phrase "constant variable" is a paradox (I think that is the right word). You have either one of the other. You declaration is either 'constant' or 'variable' (ie: it can change at run-time or it doesn't). People often use the term 'variable' and 'declaration' interchangably which is where the confusion lies.
    Anyway, onto the real problem. It seems that you want to protect your connection details (in particular the password, I would guess). Unfortunately, Java compiles not to machine-code, but byte-code which is semi-human-readable. So people, if they are inquisitive enough, will always be able to see it if they try hard enough.
    You can do one of two things:
    (1) Get an 'obfusticator'. An obfusticator is something that you run over Java source files and it completely messes it up (without modifying functionality). You then compile and the original source is such gibberish that the byte-code is very difficult to understand. However, the password will still be in there somewhere.
    (2) Don't put sensitive information into your source. Have this kind of info in external files (encrypted) and allow your class to read this file, decrypt, and use it.
    Hope that helps.
    Ben

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

  • Sqlldr and control file

    Howdy:
    I'm running Oracle 9i (9.0.2) on Redhat Linux 7.3.
    I am trying to append data from a flat file into a
    table where one of the field is timestamp(6).
    The data has fractional seconds and looks like so:
    [snip data]
    2002-12-08 22:29:38.216712
    [snip data]
    I want to use sqlldr to load the data, but when
    I try to create the control file, I am getting
    errors telling me my method is wrong.
    In my control file, I am trying to do things like:
    [snip versions of the 'UPDATED' timestamp field]
    * UPDATED TIMESTAMP "YYYY-MM-DD HH24:MI:SS"
    * UPDATED TIMESTAMP "YYYY-MM-DD HH24:MI:SS.FFF"
    * UPDATED POSITION(132:151)"TO_DATE(:UPDATED, 'YYYY-MM-DD HH24:MI:SS')"
    [snip versions ...]
    I am having no success.
    Can someone give an example of how to create
    a control file for sqlldr when defining a
    timestamp field with fractional seconds six
    digits past the decimal?
    Thanks!
    -X

    --update:
    --this is pretty much for my notes (as i'm
    --sure i will need this info again).
    --i have figured out how to fix my problem.
    --re-cap:
    --so, i'm running Oracle 9i (9.2.0) on Redhat Linux 7.2 as
    --you know.  I want to append my data from a flat file
    --into a table that i've created.  i also want to use SQLLDR
    --to do it.  i  have create a bunch of scripts to do this
    --and i was close - the problem was that in one of the
    --fields (table) was a TIMESTAMP field and i couldn't
    --figure out how to create a control file to say 'hey, there
    --is a timestamp field in there and it has fractions in
    --the seconds area ... 6 decimal places over'.
    --so, this is what my table looks like:
    [snip table]
    SQL> describe hmp_dates
    Name Null? Type
    CONTRACT CHAR(12)
    MBR_NUM CHAR(2)
    DATE DATE
    EVENT_ID NUMBER(38)
    VALUE VARCHAR2(50)
    RESULT VARCHAR2(50)
    UPDATED TIMESTAMP(6) WITH TIME ZONE
    USERNAME VARCHAR2(50)
    CLAIM VARCHAR2(50)
    [snip table]
    --this is what my data looks like:
    [snip data]
    xxxxxxxxx |02|2000-05-31|38|\N|\N|2002-12-08 22:29:38.216712|ADMIN|\N
    xxxxxxxxx | |1999-06-06|38|\N|\N|2002-12-08 22:29:38.216712|ADMIN|\N
    xxxxxxxxx | |1998-12-28|38|\N|\N|2002-12-08 22:29:38.216712|ADMIN|\N
    xxxxxxxxx | |1999-12-03|38|\N|\N|2002-12-08 22:29:38.216712|ADMIN|\N
    [snip data]
    --this is what my control file looks like:
    [snip control]
    LOAD DATA
    INFILE '/var/local/table_backup/hmp_dates_03July2003.txt'
    APPEND
    INTO TABLE HMP_DATES
    FIELDS TERMINATED BY '|' OPTIONALLY ENCLOSED BY '"'
    CONTRACT,
    MBR_NUM,
    "DATE" DATE "YYYY-MM-DD",
    EVENT_ID,
    VALUE,
    RESULT,
    UPDATED TIMESTAMP WITH TIME ZONE 'YYYY-MM-DD HH24:MI:SSXFF', *****
    USERNAME,
    CLAIM
    [snip control]
    --please note the astrisks. that is the elfin goodness. (SSXFF to denote precision
    --seconds).
    --hopes this helps someone besides me.
    -X

  • Problem in control file created through  LKM File to Oracle (SQLLDR)

    I have a fixed file ABC.txt & it has three fields/columns of length ,C1:= 4, C2 :=10 & C3:=6 & I have to use LKM File to Oracle (SQLLDR) to load data into oracle target table.
    I recieved the following error at step CALL SQLLDR in the KM
    "org.apache.bsf.BSFException: exception from Jython: Traceback (innermost last):
    File "<string>", line 3, in ?"
    Then I checked the control file log & found that the position start value & end value was not defined in control file which is created automatically by LKM
    SQL*Loader-350: Syntax error at line 14.
    Expecting positive integer, found ":".
         C1_C1     POSITION(:), "
    The control file created by ODI is & it's missing the position value.
    OPTIONS (
         SKIP=0,
         ERRORS=0,
         DIRECT=FALSE
    LOAD DATA
    INFILE "C:/SNAPON/EOL.txt"
    BADFILE "C:/SNAPON/ABC.bad"
    DISCARDFILE "C:/SNAPON/ABC.dsc"
    DISCARDMAX 1
    INTO TABLE SNAPON_W.C$_0ABC
         C1_C1     POSITION(:),
         C2_C2     POSITION(:),
         C3_C3     POSITION(:)
    Does any one know why the position value is not created in the control file .
    Edited by: neeraj_singh on Mar 3, 2011 1:25 AM

    Hi Neeraj,
    It is happening because you have not selected the mapping execution area as STAGUING .
    Open your interface , click on each and every column of your target datastore , make sure the "Execute On" is marked on "Staging Area".
    Then run your interface.
    Thanks,
    Sutirtha

  • How to dynamically create sqlldr control file using stored procedure

    I am trying to dynamically create the control file (.ctl) and execute the same using a stored procedure.I would be passing the file name as a parameter to this procedure. How do I go about doing this?
    The control file has the following structure. The file name (mktg) varies and is passed as an input to the stored procedure.
    SPOOL mktg.ctl
    LOAD DATA
    INFILE 'mktg.csv'
    INTO TABLE staging
    FIELDS TERMINATED BY ','
    TRAILING NULLCOLS
    (COMPANY_NAME,
    ADDRESS,
    CITY,
    STATE,
    ZIP)
    SPOOL OFF ;
    sqlldr scott/tiger CONTROL= mktg.ctl LOG=mktg.log BAD=mktg.bad

    We are using oracle 9i rel 2.
    I have not had much success with the creation of log and bad files using external tables when they are being used within a dynamic sql.
    Plz check this:
    Re: problems related to data loads from excel, CSV files into an oracle 9i db

  • Creating a dynamic sqlldr control file

    Hi,
    I am in need of creating a dynamic sqlldr control file that will check the flat file, delimiter and load the data in a table. The table is having all the columns but the flat file can vary time to time.
    looking forward for your valuable suggestions.
    Regards
    Rajib.

    You may want to post more explicit requirements if you want sample code. For example, what the file looks like, what variations are allowed, what variations are disallowed, an example control file that would be output, etc. Specifying the precise language you're using (there are many different shell scripting languages) would also help.
    In my experience, though, this sort of thing is almost always a one-off-- examples don't tend to be particularly helpful because every set of requirements tends to be very particular. If you have a full understanding of the requirements, and a decent understanding of your scripting language, I doubt it would take more than half a day to knock something together.
    Justin

  • Parameters / Variables in SQL Loader Control File

    Here's my problem, I have created SQL Loader control file (ctl) to load a file of employees. This loader program is registered in Oracle Applications. What I want is to pass a parameter derived from the profile like the user name of the one who executed the loader program and pass it to the loader program so that the user name info is included in the loading
    example
    input data
    123456,John,Smith
    654321,Jane,Doe
    loaded data
    123456,John,Smith,03-JUL-2009,USER13
    654321,Jane,Doe,03-JUL-2009,USER13
    the sysdate is easy because it can be defined in the column but what I really want to achieve is a parameter passed to the ctl file.
    Thanks in advance.

    Dear user!
    Please have a look at this thread.
    {thread:id=915277}
    In the last three posts I explain how to use a shellscript with AWK and SED to pass parameters to a controlfile.
    Please feel free to post again if you have some questions regarding my explanatory notes.
    Yours sincerely
    Florian W.

  • Most elegant way to accept a variable number of files?

    I am writing a program where I would like to accept a variable number of files to process. In my inexperience with LabVIEW I can think of several ways to do this, which aren't as user friendly as I'd like it to be.
    I tried an array of file path controls. This will be the easiest to implement, but what I don't like is that you can't really see all the files you've inputted at once and if you select a file and want to erase it, it will query you for a file.
    I tried a while loop with an empty file path to my Read Characters from File.vi, but I would like it so that the user can just specify which files they'd like to load without having to wait inbetween. Also, as I mentioned before, I would prefer it if the use
    r could see which files they've decided to load and have the option of taking a file out if they should so choose.
    I could try just fixing the number of files and have like 5 or so file path controls and do it like that. That seems like it would be clumsy and obviously has the problem of not being variable.
    I'm just wondering if there is something that I haven't thought of, or if I have and which avenue would be the best. I feel fine about using an array of file path indicators, but wonder how I can remove indicies that are empty.

    Dan, use the special path constant called "Temporary Directory".
    Another problem is the fact that you hardwire the path as a string ("c:\temp\...") instead of a path constant. This will make the code useless on any platform except windows.
    LabVIEW Champion . Do more with less code and in less time .

  • Different log file name in the Control file of SQL Loader

    Dear all,
    I get every day 3 log files with ftp from a Solaris Server to a Windows 2000 Server machine. In this Windows machine, we have an Oracle Database 9.2. These log files are in the following format: in<date>.log i.e. in20070429.log.
    I would like to load this log file's data to an Oracle table every day and I would like to use SQL Loader for this job.
    The problem is that the log file name is different every day.
    How can I give this variable log file name in the Control file, which is used for the SQL Loader?
    file.ctl
    LOAD DATA
    INFILE 'D:\gbal\in<date>.log'
    APPEND INTO TABLE CHAT_SL
    FIELDS TERMINATED BY WHITESPACE
    TRAILING NULLCOLS
    (SL1 DATE "Mon DD, YYYY HH:MI:SS FF3AM",
    SL2 char,
    SL3 DATE "Mon DD, YYYY HH:MI:SS FF3AM",
    SL4 char,
    SL5 char,
    SL6 char,
    SL7 char,
    SL8 char,
    SL9 char,
    SL10 char,
    SL11 char,
    SL12 char,
    SL13 char,
    SL14 char,
    SL15 char)
    Do you have any better idea about this issue?
    I thought of renaming the log file to an instant name, such as in.log, but how can I distinguish the desired log file, from the other two?
    Thank you very much in advance.
    Giorgos Baliotis

    I don't have a direct solution for your problem.
    However if you invoke the SQL loader from an Oracle stored procedure, it is possible to dynamically set control\log file.
    # Grant previleges to the user to execute command prompt statements
    BEGIN
    dbms_java.grant_permission('bc4186ol','java.io.FilePermission','C:\windows\system32\cmd.exe','execute');
    END;
    * Procedure to execute Operating system commands using PL\SQL(Oracle script making use of Java packages
    CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "Host" AS
    import java.io.*;
    public class Host {
    public static void executeCommand(String command) {
    try {
    String[] finalCommand;
    finalCommand = new String[4];
    finalCommand[0] = "C:\\windows\\system32\\cmd.exe";
    finalCommand[1] = "/y";
    finalCommand[2] = "/c";
    finalCommand[3] = command;
    final Process pr = Runtime.getRuntime().exec(finalCommand);
    new Thread(new Runnable() {
    public void run() {
    try {
    BufferedReader br_in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
    String buff = null;
    while ((buff = br_in.readLine()) != null) {
    System.out.println("Process out :" + buff);
    try {Thread.sleep(100); } catch(Exception e) {}
    catch (IOException ioe) {
    System.out.println("Exception caught printing process output.");
    ioe.printStackTrace();
    }).start();
    new Thread(new Runnable() {
    public void run() {
    try {
    BufferedReader br_err = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
    String buff = null;
    while ((buff = br_err.readLine()) != null) {
    System.out.println("Process err :" + buff);
    try {Thread.sleep(100); } catch(Exception e) {}
    catch (IOException ioe) {
    System.out.println("Exception caught printing process error.");
    ioe.printStackTrace();
    }).start();
    catch (Exception ex) {
    System.out.println(ex.getLocalizedMessage());
    public static boolean isWindows() {
    if (System.getProperty("os.name").toLowerCase().indexOf("windows") != -1)
    return true;
    else
    return false;
    * Oracle wrapper to call the above procedure
    CREATE OR REPLACE PROCEDURE Host_Command (p_command IN VARCHAR2)
    AS LANGUAGE JAVA
    NAME 'Host.executeCommand (java.lang.String)';
    * Now invoke the procedure with an operating system command(Execyte SQL-loader)
    * The execution of script would ensure the Prod mapping data file is loaded to PROD_5005_710_MAP table
    * Change the control\log\discard\bad files as apropriate
    BEGIN
    Host_Command (p_command => 'sqlldr system/tiburon@orcl control=C:\anupama\emp_join'||1||'.ctl log=C:\anupama\ond_lists.log');
    END;Does that help you?
    Regards,
    Bhagat

  • SQL Loader and control file changes for different users

    In the front end of my application I can select a data file and a control file, and load data to the table mentioned in .ctl file. Every user who logs in uses the same .ctl file and so loads onto the same table. Now I want the user to load data onto the table in his own schema. I can get the username of the user currently logged in and i want to insert it into that username.table. So can i copy the contents of the .ctl file into a variable, modify it into username.table in that string and pass that variable as a parameter to the sqlldr command instead of the .ctl file.
    Or is there a better way how I can modify the same control file everytime to change tablename to username.tablename in .ctl file and pass to sqlldr to load data to table in local user schema table.
    Thanks and Regards

    Thanks for the reply .. user do have their user credentials but only for the application ... but all users use a common loader and control file once they log into the application. So irrespective of which user is logged in he selects the same control file and loads to the same table mentioned in the control file .. i instead want user to be able to load to the table in control file but into his schema like username.tablename instead of just the tablename mentioned in .ctl file.

  • Load data with SQL Loader link field between CSV file and Control File

    Hi all,
    in a SQL Loader control file, how do you specify link with field in CSV file and Control file?
    E.g. if I wat to import the record in table TEST (col1, col2, col3) with data in csv file BUT in different position. How to do this?
    FILE CSV (with variable position):
    test1;prova;pippo;Ferrari;
    xx;yy;hello;by;
    In the table TEST i want that col1 = 'prova' (xx),
    col2 = 'Ferrari' (yy)
    col3 = default N
    the others data in CSV file are ignored.
    so:
    load data
    infile 'TEST.CSV'
    into table TEST
    fields terminated by ';'
    col1 ?????,
    col2 ?????,
    col3 CONSTANT "N"
    Thanks,
    Attilio

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

Maybe you are looking for

  • Phone service over Wi-Fi

    I am looking at purchasing a Pre when it comes out this weekend. Does anyone know whether it has the capability to use the phone over broadband? I have a friend that just purchased another smartphone that has the ability to use the phone over his wir

  • CCM 5.0(2) and Conference Connection

    I see in the compatibility matrix that this combination in not supported, but does anyone know if it will work? Our efforts to retire CCC have been delayed and our CCM 5.0 upgrade starts in the morning. We can live with it even if it works poorly, bu

  • Why not using delta pkg.tar.gz?

    hello everybody, im new archlinux user, so i have question. why archlinux dont using delta pkg.tar.gz packages? opensuse provides updates in delta rpm binary form. instead re-downloading all new packages, it would be nice to download (update) delta p

  • Example of creating  ALV double click event that can be used in ANY Program

    Once you get the hang of OO you can really create useful generalized code that can be used in a huge number of situtations. Double click on ALV is often wanted Right  here goes to implement a generalized double click action that returns the row, colu

  • Color Corrector Window

    Does any one know how to keep the color corrector window open. I am running dual monitors and would like to keep my color corrector window open, but everytime I click on a new clip in the view it reverts back to the viewer and dissapears from my seco