SQL Loader:  Is it possible to set a variable?

Hallo All,
I am loading data with SQL Loader and find that I can set particular fields to particular values using 'CONSTANT'. That's great. However, I am loading multiple files into the same format and so would like to 'label' each load. This would be done by setting a variable before each load and then using this to write the load month (e.g. '200901') into the column 'SOURCE_FILE' in the destination table.
I imagine the syntax would look something like this ...
LOAD DATA
strSource = '200809'
INFILE 'source_data_200809.csv'
strSource = '200810'
INFILE 'source_data_200810.csv'
strSource = '200811'
INFILE 'source_data_200811.csv'
APPEND
INTO TABLE DESTINATION_TABLE
FIELDS TERMINATED BY ";" OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
(CUSTNO char,
BARCODE char,
NAME char,
SOURCE_FILE char :strSource)
Then, for each load I would reference the variable strSource and write the appropriate month into a column/field in the table.
I have been googling and trawling through the documentation but I cannot seem to find a way to do this. Is it possible? Or maybe there is another method/way/trick to do this? Or maybe it is just a question of syntax?
Any ideas?
Regards,
Alan Searle

Hi Kamran,
I took a look at that thread and there were some tips including details about sending parameters through the command line ...
SQLLDR CONTROL=controlfile.ctl, DATA=yourdatafile.csv
But here I would need to also be able to send a parameter that I could pick up and use within SQL Loader. This might be ...
SQLLDR CONTROL=controlfile.ctl, DATA=source_data_200809.csv VAR=200809
... here I would write the value '200809' to a column in the table being loaded (so that I could track back to the source of the load).
I checked the documentation but it doesn't seem to be possible to send a variable in this way.
Any other tips?
Regards,
Alan

Similar Messages

  • Error trying to run SSIS Package via SQL Server Agent: DTExec: Could not set \Package.Variables[User::VarObjectDataSet].Properties[Value] value to System.Object

    Situation:
    SSIS Package designed in SQL Server 2012 - SQL Server Data Tools
    Windows 7 - 64 bit.
    The package (32 bit) extracts data from a SQL Server db to an Excel Output file, via an OLE DB connection.
    It uses 3 package variables:
    *) SQLCommand (String) to specify the SQL Statement to be executed by the package
    Property path: \Package.Variables[User::ExcelOutputFile].Properties[Value]
    Value: f:\Output Data.xls
    *) EXCELOutputFIle (String) to specify path and filename of the Excel output file
    Property path: \Package.Variables[User::SQLCommand].Properties[Value]
    Value: select * from CartOrder
    *) VarObjectDataSet (Object) to hold the data returned by SQL Server)
    Property path: \Package.Variables[User::VarObjectDataSet].Properties[Value]
    Value: System.Object
    It consists out of 2 components:
    *) Execute SQL Task: executes the SQL Statement passed on via a package variable. The resultng rows are stored in the package variable VarObjectDataSet
    *) Script Task: creates the physical output file and iterates VarObjectDataSet to populate the Excel file.
    Outcome and issue:The package runs perfectly fine both in SQL Server Data Tools itself and in DTEXECUI.
    However, whenever I run it via SQL Server Agent (with 32 bit runtime option set), it returns the errror message below.
    This package contains 3 package variables but the error stating that a package variable can not be set, pops up for the VarObjectDataSet only.  This makes me wonder if it is uberhaupt possible to set the value of a package variable
    of type Object.
    Can anybody help me on this please ?
    Message
    Executed as user: NT Service\SQLSERVERAGENT. Microsoft (R) SQL Server Execute Package Utility  Version 11.0.2100.60 for 32-bit  Copyright (C) Microsoft Corporation. All rights reserved.    Started:  6:40:20 PM  DTExec: Could
    not set \Package.Variables[User::VarObjectDataSet].Properties[Value] value to System.Object.  Started:  6:40:20 PM  Finished: 6:40:21 PM  Elapsed:  0.281 seconds.  The package execution failed.  The step failed.
    Thank you very much in advance
    Jurgen

    Hi Visakh,
    thank you for your reply.
    So, judging by your reply, not all package variables used inside a package need to be set a value for when run in DTEXEC ?
    I already tried that but my package ended up in error (something to do with "... invocation ...." and that error is anything but clearly documented. Judging by the error message itself, it looks like it could be just about anything. that is why I asked my
    first question about the object type package variable.
    Now, I will remove it from the 'set values' list and try another go cracking the unclear error-message " ... invocation ...". Does an error message about " ... invocation ..." ring any bells, now that we are talking about it here ?
    Thx in advance
    Jurgen
    Yes exactly
    You need to set values only forthem which needs to be controlled from outside the package
    Any variable which gets its value through expression set inside package or through a query inside execute sql task/script task can be ignored from DTExec
    Ok I've seen the invocation error mostly inside script task. This may be because some error inside script written in script task. If it appeared after you removed the variable then it may because some reference of variable existing within script task.
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Is it possible to set bind variable for picklist?? for messageChoice

    we are trying to develop one new page in local JDeveloper.
    we have requirement for passing a bind variable to a picklist. is it possible?
    Item Type : messageChoice
    Query:
    SELECT DISTINCT TO_CHAR (effective_date, 'YYYY') TYPE
    FROM pay_assignment_actions a, pay_payroll_actions b
    WHERE a.payroll_action_id = b.payroll_action_id
    AND assignment_id =
    (SELECT assignment_id
    FROM per_assignments_x
    WHERE person_id = :person_id AND primary_flag = 'Y'
    AND assignment_type = 'E')
    AND a.action_status = 'C'
    AND b.payroll_action_id IN (SELECT payroll_action_id
    FROM pay_payroll_actions_v
    WHERE action_type IN ('P'))
    AND b.payroll_action_id IN (SELECT payroll_action_id
    FROM xxilo_pre_payments)
    ORDER BY 1 DESC
    processRequest() code:
    PayslipAMImpl am=(PayslipAMImpl)pageContext.getApplicationModule(webBean);
    YearPicklistVOImpl yvo=(YearPicklistVOImpl)am.getYearPicklistVO1();
    Number t = new Number(pageContext.getEmployeeId());
    yvo.setWhereClauseParams(null);
    yvo.setWhereClauseParam(0,t);
    for this query & code we are getting
    ERROR:
    java.sql.SQLException: Missing IN or OUT parameter at index:: 1
    if we hardcoded person_id in query to some value then we are getting results without any error.

    user603084 ,
    In the query you have specifies bind variable as :person_id , but in your VO execution code you are setting value for bind variable :1
    yvo.setWhereClauseParam(0,t);
    You need to change the bind variable in query , like :1
    and then execute the query of VO, as you have done. Also do executeQuery, after setting bind variables.
    --Mukul                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Is it possible to set a variable in a program from outside before calling

    Suppose I have a program as follows
    Report Program1.
      data: prog1data(10) type c.
    start-of-selection.
      perform Prog1Form.
    form Prog1Form.
      write: prog1data.
    endform.
    Now if I have another program which calls the Prog1Form from outside, is there some way I can set value of variable prog1data from my second program before I call Prog1Form routine e.g
    Report Program2.
    start-of-selection.
    ->>>>Somehow set the variable prog1data in Program1 ?
      perform PROG1FORM in PROGRAM1.
    Will give points for the right answer. Thanks for reading.

    HI,
      use Export statment in calling program and import statment in the called program.
    Calling program
      export variable to memory id 'VAR'.
    Called Program
      import variable from memory id 'VAR'
    Thanks
    Mahesh

  • SQL*Loader-266: Unable to locate character set handle for None

    Hi All,
    I am getting "SQL*Loader-266: Unable to locate character set handle for None" through sql loader.
    NLS Parameters are :
    NLS_LANGUAGE AMERICAN
    NLS_TERRITORY AMERICA
    NLS_CURRENCY $
    NLS_ISO_CURRENCY AMERICA
    NLS_NUMERIC_CHARACTERS .,
    NLS_CALENDAR GREGORIAN
    NLS_DATE_FORMAT DD-MON-RR
    NLS_DATE_LANGUAGE AMERICAN
    NLS_CHARACTERSET AL32UTF8
    NLS_SORT BINARY
    NLS_TIME_FORMAT HH.MI.SSXFF AM
    NLS_TIMESTAMP_FORMAT DD-MON-RR HH.MI.SSXFF AM
    NLS_TIME_TZ_FORMAT HH.MI.SSXFF AM TZR
    NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH.MI.SSXFF AM TZR
    NLS_DUAL_CURRENCY $
    NLS_NCHAR_CHARACTERSET UTF8
    NLS_COMP BINARY
    NLS_LENGTH_SEMANTICS BYTE
    NLS_NCHAR_CONV_EXCP FALSE
    Kindly help
    Thanks in advance

    Please, provide the exact value of the NLS_LANG environment variable, if defined in the shell environment of SQL*Loader, and the NLS_LANG Registry setting, if on Windows. Please, provide the SQL*Loader control file.
    -- Sergiusz

  • Loading Objects with SQL*Loader

    When loading a column object with SQL*Loader, is it possible to specify a column specific 'TERMINATED BY' clause in the control file?
    I've successfully defined column-level termination characters for regular columns and nested tables, but can't seem to find any way of achieving the same result with column objects.

    When loading a column object with SQL*Loader, is it possible to specify a column specific 'TERMINATED BY' clause in the control file?
    I've successfully defined column-level termination characters for regular columns and nested tables, but can't seem to find any way of achieving the same result with column objects.

  • SQL loader : how to populate a calculated feild of a table?

    Hi All,
    I have a table which has total 92 columns, among them 6 feilds are calculated using few other fields of the same table.
    i have a csv file , which has only 86 feilds .
    during upload data using sql loader, is it possible to calculate other 6 feilds and upload them along with 86 fields ?
    Or any other method to populate the calculated values?
    Thanks in advance,
    Archana

    Hi Archana,
    You can have a script file with the required update commands and execute that script after the Loader loads the data to have them updated.
    But it is not a good practice to store the calculated values in the fields.
    Whenever required you can have them as a calculation in your select statements instead of storing them in the table.
    Unfortunately if the base values get changed you would be forced to recalculate and store them if you have them in the table.
    Regards,
    S.Muthukumar.

  • How to Load Data with SQl Loader to a Form (D2k,VB,Applet.Etc.,)

    hi.,
    By SQL LOADER iam able to Transfer data to Oracle Database, from a Flat File System.
    But now i want to Transfter the data from Flat Files, to Oracle Apps/VB/D2k Etc.,
    with help of SQL Loader.,
    is it possible to do..?
    Thanks in Advance,
    With Regards.,
    N.GowriShankar.

    For the Applications you can use file handling built-ins such as TEXT_IO, UTL_FILE, etc. You can write a batch program for sqlldr and can invoke it from front end Applications.

  • Sql Loader problem.Urgent pls

    Hi experts.
    Now i am using Oracle 7.3 . i am want to know one thing in sql loader. is it possible to load data with out using one field. i want to divide and load into one field. I have given one example here. pls give me the logic how i can load like this.
    load data
    infile 'xxx.prn'
    append
    into table xyy
    PRC decimal external "to_number(position(191:197))/to_number(position(2
    05:211))"
    thanks in advance
    venkat

    Would you please stop posting the same question again and again?
    This is really boring.

  • Installing SQL LOADER

    hi there,
    I need to install only SQL LOADER from oracle 9i Enterprise edition software.How it is possible?
    Please tell me the steps...

    SQL*loader is implicitly installed when you performed the enterprise edition installation.
    It is not even required to be an enterprise edition for it to be installed, it can be installed from any Oracle Edition (rdbms install), as well as from the client.
    If you are not able to find the sql*loader executable:
    # make sure your PATH environment variable includes the ORACLE_HOME\bin ORACLE_HOME is the directory where Oracle was installed.
    # Executable is sqlldr.exe
    Madrid.

  • Cannot call SQL-Loader in php

    Hello,
    I'm currently trying to call the SQL Loader in a php-script in order to enable users to upload data by themselves by a simple button-click. I tried several things however everytime I'm clicking on the button, nothing happens.
    my code looks as follow:
    if ($upload_csv == "1") {
    $command="SQLLDR *Scheme*/*Passwrd*@*server* log='*server*/abc.log' control='*server*\abc.ctl'";     
    chdir("\\*server*\UPLOAD");
    $exec(command);
    I also tried it in several other ways, for examle calling the sql-loader-command directly or without the command-variable, however nothing worked.
    Am I doing something wrong

    Actually we're using MS Windows Server 2003 and also the call of the SQL Loader shouldn't be any problem as I called the Loader via batch-file on the server directly and it worked just fine - only calling the Loader or even the batch-file via PHP doesn't work...
    Well, I tried something out and moved the php-script to another folder and all of a sudden I started to get error-messages printed on the sceen.
    Tried it then in 2 ways - once with the command "$sell_status = shell_exec(abc.bat);" and got this error message back: CGI Error - The specified CGI application misbehaved by not returning a complete set of HTTP headers.
    Afterwards I also tried it with the exec()-Command and got this error-message back: Fatal error: Function name must be a string in - C:\Inet\root\Intranet\db_admin\test.php on line 14

  • Setting mutliple variables and filters in operators

    Hi all,
    Playing around with the new liquid markup and loving it. Have two questions though that I couldn't find answers to in the docs.
    1) Is it possible to set multiple variables in one line, or some better way than what I'm currently doing? At present I'm adding a new line per variable, so
    {% assign var1 = 1 %}
    {% assign var2 = 2 %}
    Just thought there might be an easier way, like perhaps
         assign var1 = 1,
         assign var2 = 2
    2) Is it possible to use filters in operators? If so I may be doing it wrong;
    {% if numericVar1 | modulo: numericVar2 == 0 %} **do whatever **{% endif %}
    My first thought is it is evaluating the second bit and using that for the modulo. So, if numericVar2 was "0", it would be trying to do "numericVar1 | modulo: (numericVar2 == 0)", rather than "(numericVar1 | modulo: numericVar2) == 0".
    I also thought perhaps it might be related to the bug linked below, but I've had no issues in general using variables alone with filters, only when in operators.
    Bug: Liquid math filters don't work with module data
    Edited because I hit post too soon.

    Hi there,
    1. No, its not a high end language, what your doing is fine there.
    2. Filters in operators work, but not all cases.

  • How to set default directory for SQL LOADER

    hi all,
    i wanted to know how can we setup a default directory for SQL LOADER if at all we can. i connot place my control and data files in local system and use them at command prompt. rather i wanted to know if we can set default directory that the loader can use. this requirement is basically to enable all the clients to upload the data placed on the server and use the loader utility.
    thanks in advance,
    Basavraj

    Ella,
    You don't say which version of SQL Developer you are using via Citrix, but just setting the SQLDEVELOPER_USER_DIR hasn't worked for a long time (see Re: SQLDEVELOPER_USER_DIR does not function anymore). Also, since version 1.5, the default for the user directory (now set via ide.user.dir as shown below) is under the user profile area (relative to %APPDATA%), which you should be able to write to, even on Citrix.
    Assuming that neither of those help, you will need to get whoever installed SQL Developer on the Citrix C: drive to modify the sqldeveloper.conf to have a line like, where the path exists for everyone who will be using the shared SQL Developer (assumes everyone has a H: drive):
    AddVMOption -Dide.user.dir=H:\sqldeveloperAn alternative (depending on how you start SQL Developer via Citrix), is to create your own shortcut to start SQL Developer with something like:
    sqldeveloper -J-Dide.user.dir="%SQLDEVELOPER_USER_DIR%"theFurryOne

  • SQL * Loader loading ORDSYS object setting properties

    Hi,
    I have table where am storing image as ORDSYS.ORDIMAGE.
    I am using SQL*loader to load the image coloum. Below shown is the extract of the load file
    Image COLUMN OBJECT
              source COLUMN OBJECT
                   localData_fname FILLER CHAR(128),
                   localData LOBFILE (Image.source.localData_fname) TERMINATED BY EOF
    with this, I am able to load the image. now i want to set the other properties of ORDImage object like description.
    How can i do that? please can anyone help me in this?
    Edited by: 896943 on Dec 8, 2011 6:23 PM

    There is no 'setDescription' method available with the ordimage type. You can use putMetadata if that works for you.
    Otherwise, you would have to build a custom data-type based on the ordimage type in order to store your 'description'.

  • Urgent :SQL Loader Arabic Character Set Issue

    HI all,
    I am loading arabic characters into my database using SQL Loader using a fixed length data file. I had set my characterset and NLS_LANG set to UTF8.When I try to load the chararacter 'B' in arabic data i.e. ' لا ' , it gets loaded as junk in the table. All other characters are loaded correctly. Please help me in this issue and its very urgent.
    Thanks,
    Karthik

    Hi,
    Thanks for the responses.
    Even after setting the characterset to arabic and the problem continues to persist. This problem occurs only with the character "b".
    Please find my sample control file,input file and nls_parameters below:
    My control file
    LOAD DATA
    characterset UTF8
    LENGTH SEMANTICS CHAR
    BYTEORDER little endian
    INFILE 'C:\sample tape files\ARAB.txt'
    replace INTO TABLE user1
    TRAILING NULLCOLS
    name POSITION(1:2) CHAR(1),
    id POSITION (3:3) CHAR(1) ,
    salary POSITION (4:5) CHAR(2)
    My Input file - Fixed Format
    ?a01
    ??b02
    ?c03
    The ? indicates arabic characters.Arabic fonts must be installed to view them.
    NLS_PARAMETERS
    PARAMETER     VALUE
    NLS_LANGUAGE     ARABIC
    NLS_TERRITORY     UNITED ARAB EMIRATES
    NLS_CURRENCY     ?.?.
    NLS_ISO_CURRENCY     UNITED ARAB EMIRATES
    NLS_NUMERIC_CHARACTERS     .,
    NLS_CALENDAR     GREGORIAN
    NLS_DATE_FORMAT     DD/MM/RR
    NLS_DATE_LANGUAGE     ARABIC
    NLS_SORT     ARABIC
    NLS_TIME_FORMAT     HH12:MI:SSXFF PM
    NLS_TIMESTAMP_FORMAT     DD/MM/RR HH12:MI:SSXFF PM
    NLS_TIME_TZ_FORMAT     HH12:MI:SSXFF PM TZR
    NLS_TIMESTAMP_TZ_FORMAT     DD/MM/RR HH12:MI:SSXFF PM TZR
    NLS_DUAL_CURRENCY     ?.?.
    NLS_COMP     BINARY
    NLS_LENGTH_SEMANTICS     CHAR
    NLS_NCHAR_CONV_EXCP     FALSE

Maybe you are looking for