Using CASE insted of DECODE in Control File

Hi,
I have seen a lot of examples of DECODE in a Control File. I know how to use DECODE, but I prefer CASE. Does anyone know, if it is allowed, and is the synatx the same as standard CASE statements. I am going to try it, but this is just so that I don't try all different variations and then find that it is not available.
Another thought is could you use an IN List Statement.
Something like IF :col1 IN('A', 'AB') THEN "wow".
I know the IN is going to be jsut a WISH...
--Thanks
Message was edited by:
pshah2k

Yep, here's an example:
LOAD DATA
INFILE '/home/ennisbi/DBLOAD/data/xxx_2000.csv'
APPEND INTO TABLE STG_VOLUME
FIELDS TERMINATED BY ','
TRAILING NULLCOLS
EFFECTIVE_DATE DATE "YYYYMM",
SSB_ID,
SEDOL_OR_CUSIP,
AVG_BID_ASK_SPREAD_DIV2,
AVG_SHARE_VOLUME,
ANNUALIZED_VOLATILITY "CASE WHEN :ANNUALIZED_VOLATILITY='NC' then 0 else TO_NUMBER(:ANNUALIZED_VOLATILITY) end"

Similar Messages

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

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

  • Using translate for date in the control file !!

    Hi,
    I am having data file where in i expect date but get non-numeric character.
    I am generating control file dynamically (programatically).
    While creating control file i know that here the type of data will be date so i put datatype as date. But at one place i got non numeric character instead of date.
    Now i want to put somekind of logic built in my dynamic generation which will check whether if value within that column is character then make it null and then load data. And if it is numeric keep it as it it.
    i.e.
    if(non-numericChars)
    make value null before loading.
    else
    keep the value as it and then load it.
    I heard that with translate function we can do that. Right ?
    So if i have a line like this in my control file:
    column_Name date "MM/DD/YYYY HH:MI:SS AM"
    How should i write the above statement to put the above mentioned logic.
    Any help would be highly appreciated.
    Regards,
    Dipesh

    and Perhaps TO_DATE can help you :
    TO_DATE
    Syntax
    to_date::=
    Text description of to_date
    Purpose
    TO_DATE converts char of CHAR, VARCHAR2, NCHAR, or NVARCHAR2 datatype to a value of DATE datatype. The fmt is a date format specifying the format of char. If you omit fmt, then char must be in the default date format. If fmt is 'J', for Julian, then char must be an integer.
    Note:
    This function does not convert data to any of the other datetime datatypes. For information on other datetime conversions, please refer to TO_TIMESTAMP, TO_TIMESTAMP_TZ, TO_DSINTERVAL, and "TO_YMINTERVAL".
    The default date format is determined implicitly by the NLS_TERRITORY initialization parameter, or can be set explicitly by the NLS_DATE_FORMAT parameter.
    The 'nlsparam' has the same purpose in this function as in the TO_CHAR function for date conversion.
    Do not use the TO_DATE function with a DATE value for the char argument. The first two digits of the returned DATE value can differ from the original char, depending on fmt or the default date format.
    Note:
    This function does not support CLOB data directly. However, CLOBs can be passed in as arguments through implicit data conversion. Please refer to "Datatype Comparison Rules" for more information.
    See Also:
    "Date Format Models"
    Examples
    The following example converts a character string into a date:
    SELECT TO_DATE(
    'January 15, 1989, 11:00 A.M.',
    'Month dd, YYYY, HH:MI A.M.',
    'NLS_DATE_LANGUAGE = American')
    FROM DUAL;
    TO_DATE('
    15-JAN-89
    The value returned reflects the default date format if the NLS_TERRITORY parameter is set to 'AMERICA'. Different NLS_TERRITORY values result in different default date formats:
    ALTER SESSION SET NLS_TERRITORY = 'KOREAN';
    SELECT TO_DATE(
    'January 15, 1989, 11:00 A.M.',
    'Month dd, YYYY, HH:MI A.M.',
    'NLS_DATE_LANGUAGE = American')
    FROM DUAL;
    TO_DATE(
    89/01/15
    http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540/functions137a.htm#SQLRF06132
    Joel P�rez

  • 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 trim and date function in control file

    I want to load "?30/12/2005 22:13?" into the table table1 and remove the "?" characters.
    LOAD DATA
    INTO TABLE TABLE1
    FIELDS TERMINATED BY ","
    (ORDER_DATE "TRIM('?', 'MM/DD/YYYY HH24:MI')"
    What's wrong with the above statement ?
    thanks.

    in addition, can i specify the starting row from the text file to load the data ?
    e.g. i only want to load from the 10th row Use SKIP 9 for that
    http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96652/ch04.htm#1004940
    and to eliminate the last 2 rows of the text file.There is no command for that, but if these rows can be identified through some pattern you could use conditional loading and exclude these rows
    http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96652/ch05.htm#1005658

  • How to Use Sequence created in Oracle Database in SQL Ldr Control file

    Hi,
    I created a sequence in oracle database. How will use the sequence in SQL loader Control file.
    Thanks in advance

    Hi,
    You might get a good response to your post in the forum dedicated to data movement , including SQL*Loader . You can find it here Export/Import/SQL Loader & External Tables
    Regards,

  • Multiplex control files in Oracle 10g...

    Hi ,
    the Oracle documentation , in one of its books points out....:
    'Once the disk drive is repaired, the damaged control file can be restored using the intact copy of the control file from the other disk and the instance can be restarted'.
    Is it achievable automatically.... or using some kind of sql commands and which , if any.....?????
    Regards,
    Simon

    there's a parameter called
    control_files
    in your spfile/pfile whichever you use.
    You can just multiply as many control files as you wish at OS level (copy) and list them in the parameter, then start your database.

  • Control file

    Control File stores this info...
    *** The timestamp of the database creation
    Q) what is the use of storing this info in control file?
    Info from :
    http://download-uk.oracle.com/docs/cd/B10501_01/server.920/a96521/control.htm
    2)
    Control file stores info for each database,
    means Multiple databases -->Multiple Control Files.
    Q) why there are so many files as init<sid>.ora and control_filea. why these all files are not merged into 1 file and why not SYS schema dict. not stores this all info as SQL server stores these into 1 place and manages itself.
    Ya i know all the files and their configuration and the steps in startup database. pls provide me why all these files can't be merged into 1 file.
    Manish

    Why do you think it might be wrong?
    APC

  • Using CASE in OWB

    There is a new article on the OTN/OWB site re. Using CASE in OWB. Very helpful, however I think ther eis a typo. The following paragraph states that CASE does not work in row-based mode. Shouldn't it say DECODE does not work in row-based mode?
    CASE vs. DECODE
    Warehouse Builder generates various types of code, some in row-based mode, some in set-based mode. To guarantee that the code works in all environments it is recommended to use CASE instead-of DECODE. The CASE statement does not work in row-based mode generation in an Oracle8i database.
    Chris Busch
    [email protected]

    Hi Chris,
    Actually, in 8.1.7 the CASE statement has equal limitations as the decode statement. That means it works in SQL context only. For Oracle 9i this has been resolved in the server and as of 9i CASE works in all modes of code.
    Therefore you would use a case statement in the same way you would use decode on 8.1.7. Hence this is not a typo.
    Hope this helps,
    Jean-Pierre

  • Recreating Control File

    Hi
    Can anybody explain when to use "RESETLOGS" and "NORESETLOGS" option while making backup of Control File to TRACE and whats the purpose of using it?
    ALTER DATABASE BACKUP CONTROL FILE TO TRACE RESETLOGS/NORESETLOGS;
    TIA
    Aqueel.

    read the following discussion from asktom site. Very informative and helpful.
    http://asktom.oracle.com/pls/ask/f?p=4950:8:2270402190261165858::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:311016722068
    Jaffar

  • Can we use replace function in bursting control file?

    Hi All,
    Greetings!!!!!!!!!!
    Have a doubt can we use sql functions like replace,nvl,decode.. in xml bursting control file.
    Please let me know if there is a option.
    awaiting reply...
    Thanks
    Rajesh

    In Expression operator or in Filter, etc. you can type function name by hand.
    Oleg

  • In case of a DB crash what happens to the status of the Control File

    When a DB is crashed will the Control file that exists in the OS also get corrupted, What happens to the Data Files , how to recover the Control files and Data Files , the DB in case there isn't any Backup media or any Dump available on the DB.

    The only one way to recover a database is to be in archivelog mode.
    And if I said about recover stricto sensu, that's because even in noarchivelog mode we need to use the command recover until cancel before an open with resetlogs option, even if we haven't any redo/archive logs. That fake a recover, this is what we say a mimic recover. Which is not a recover stricto sensu like it can be the case with archivelog mode.
    Nicolas.

  • Using archivelog and control file from other Oracle server

    I am still bothered with my backup process.
    I have 2 AIX boxes (same model, say A and B); both have BAAN 5 and Oracle 10g R2 on. Right now my colleague insists to use the export pump (cold backup) from Prod Oracle server (A) to restore the Oracle server on Box B. The Prod server has the archivelog mode turn on. But it will miss any transaction data from import pump till the crash point of Box A. So this is my confusion.
    Can I pass the control files and archivelog files form Box A (prod server) to Box B and use them to restore the Box B as the latest Prod server? How?
    I tried to convince them to use the RMAN backup? But not successful?
    I think the best way is probably to use the Oracle Data guard. However, there is always one concern to my manager and colleague, that such process will cause the data on the restored server (failover, Box B) not recognizable by the BAAN, which define the objects (tables).
    Thanks

    Performing a logical backup is not useful to restore to the point of failure. The only valid and available option is a hot backup/archivelog mode. Your recovery manager backup perform a controlfile and redologfile backup, so those can be restored at the destination. You must take care of the way you perform the backup, and ensure the paths where your backup is being deposited are visible by the second node. A shared storage with same mount points is suitable in this case. A tape robot configured at both nodes is also a suitable solution.
    Recovery manager perfoms a controlfile and spfile restore, too. This rman command perform the action:
    SET DBID <DBID of the database,for which you want to restore the controlfile>;
    RESTORE CONTROLFILE FROM <name_of_backupiece_which_contains_the_controlfile backup>';
    I don't see any problem on the recovery manager side, and technically speaking, on the Oracle side it is perfectly possible to restore your database at a remote location. I don't know what happens on the BAAN side, if you are required to have it configured to be operative on the target node. You could try to clone your database at the node B, configure BAAN and prepare the proceduere in case of failure.
    Configuring a dataguard is also a recomended action. So it is to think about Cold Failed Over clusters. I have recently performed a CFC configuration with BAAN. No problem it works smoothly.
    ~ Madrid.

  • Use Control File to load data in BW7.0

    Hi All,
    I have a requirement to load data in BW using control file. The development is done in in BW 7.0. In BW 3.5 there is an option of FILE IS ( Control File or Data File ). Please suggest how to simulate the same in BW 7.0
    Regards,
    Vikram

    Hi Vikram,
    Please have the contents of a sample control file. The file should be saved as ".TXT".
    FILENAME = C:\test.csv
    FILETYPE = CSV
    LOCATION = C
    FS = ,
    ESCAPE = "
    DECIMALPOINT = ,
    1000SEPARATOR = .
    RECCOUNT = 8
    RECSIZE = 53
    PACKETSIZE = 1000
    Filename should contain the path of the CSV file
    Filetype is CSV
    location is 'C' for Workstation and 'A' for Application Server
    FS contains field seperator ',' in our case
    RECCOUNT contain the Rec. Count
    RECSIZE is the Max DB size of the a single row ( this can be evaluated by the Total DB Size of a single Line of the Target BW Structure as well ).
    The content of my sample test.csv are
    1234567890,10,9999999999,,,15,01/01/2005
    1234567891,20,9999999999,,,30,01/01/2005
    1234567892,30,9999999999,,,0,01/01/2005
    1234567893,10,9999999999,,,5,01/01/2005
    1234567894,20,9999999999,,,6,01/01/2005
    1234567895,40,9999999999,,,10,01/01/2005
    1234567896,10,9999999999,,,5,02/01/2005
    1234567897,20,9999999999,,,6,02/01/2005
    Please let me know if there are any further concerns.
    Regards,
    Shrey
    Edited by: Shrey SAP BI on Mar 8, 2010 4:13 PM

Maybe you are looking for