Sql Loader with new column

Hi All,
I have 20 text files which have large amount of data. I need to load these data into oracle db. Each of these text files having header as column name which are same in order. Now my manager ask me to load these data in database like that last column should be the file name, so that he can track from which text file data is from. Can anybody help me to do this using sql loader.
Example:
temp1.txt temp2.txt
col1 col2 col1 col2
118 'B' 100 'J'
245 'D' 110 'K'
160 'A' 200 'N'
Now i need to load data into a database table from these text file as-------
Table Name: Temp
col1 col2 FileName
118 'B' temp1
245 'D' temp1
160 'A' temp1
100 'J' temp2
110 'K' temp2
200 'N' temp2

you can load from multiple input files provided that the files use the same record format by repeating the INFILE clause. Here is an example:
load data
infile file1.dat
infile file2.dat
infile file3.dat
fields terminated by "," optionally enclosed by '"' trailing nullcols
( column1,
  column2 )

Similar Messages

  • Problem using SQL Loader with ODI

    Hi,
    I am having problems using SQL Loader with ODI. I am trying to fill an oracle table with data from a txt file. At first I had used "File to SQL" LKM, but due to the size of the source txt file (700MB), I decided to use "File to Oracle (SQLLDR)" LKM.
    The error that appears in myFile.txt.log is: "SQL*Loader-101: Invalid argument for username/password"
    I think that the problem could be in the definition of the data server (Physical architecutre in topology), because I have left blank Host, user and password.
    Is this the problem? What host and user should I use? With "File to SQL" works fine living this blank, but takes to much time.
    Thanks in advance

    I tried to use your code, but I couldn´t make it work (I don´t know Jython). I think the problem could be with the use of quotes
    Here is what I wrote:
    import os
    retVal = os.system(r'sqlldr control=E:\Public\TXTODI\PROFITA2/Profita2Final.txt.ctl log=E:\Public\TXTODI\PROFITA2/Profita2Final.txt.log userid=MYUSER/myPassword @ mySID')
    if retVal == 1 or retVal > 2:
    raise 'SQLLDR failed. Please check the for details '
    And the error message is:
    org.apache.bsf.BSFException: exception from Jython:
    Traceback (innermost last):
    File "<string>", line 5, in ?
    SQLLDR failed. Please check the for details
         at org.apache.bsf.engines.jython.JythonEngine.exec(JythonEngine.java:146)
         at com.sunopsis.dwg.codeinterpretor.k.a(k.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.scripting(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.execScriptingOrders(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.execScriptingOrders(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTaskTrt(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSqlC.treatTaskTrt(SnpSessTaskSqlC.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTask(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessStep.treatSessStep(SnpSessStep.java)
         at com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java)
         at com.sunopsis.dwg.cmd.DwgCommandSession.treatCommand(DwgCommandSession.java)
         at com.sunopsis.dwg.cmd.DwgCommandBase.execute(DwgCommandBase.java)
         at com.sunopsis.dwg.cmd.e.i(e.java)
         at com.sunopsis.dwg.cmd.h.y(h.java)
         at com.sunopsis.dwg.cmd.e.run(e.java)
         at java.lang.Thread.run(Unknown Source)

  • Sql Loader with TSN environment variable.

    Sql loader command works fine if I have TSN entry in my system,Can I use SQL Loader with in any other way ie by use of some environment variable???
    What are the different ways I can use sql ldr ???

    952189 wrote:
    Sql loader command works fine if I have TSN entry in my system,Can I use SQL Loader with in any other way ie by use of some environment variable???
    What are the different ways I can use sql ldr ???
    >Sql loader command works fine if I have TSN entry in my system,Can I use SQL Loader with in any other way ie by use of some environment variable???
    What are the different ways I can use sql ldr ???
    if sqlldr is run on DB Server system, then no tnsnames.ora file is required.

  • SQL*loader support database columns Of Binary Double/Float

    Does SQL*loader support database columns Of Binary Double/Float when applying Direct Path?

    Why not use Google and find out for yourself.
    The first hit on Google is this
    Go see for yourself
    Regards
    FJ

  • Each time master data full load removes previous data and load with new ?

    We load company code (0COMP_CODE) master data (full load).
    1st day, we check company code master data, the record count is 150, 2nd day, the record count is 90.  It sounds like the master data full load each time would clean the previous data and load with new data, am I right?  If what I guess is right, then what setup is controlling this?
    Thanks

    I dont think it does cleanup.
    MD records in the new load simply overwrite the records already present in the master data.
    I mean if same record comes again its overwritten.If new record it gets added.
    I wouldnt expect number of records to reduce drastically from 150 to 90.
    Maybe before MD activation records could be more(as there will be both M(modified) and A(active) records).
    cheers,
    Vishvesh

  • How to use SQL loader with DBF fixed format record

    Hi everybody!
    My situation is that: I want to use SQL loader with Foxpro DBF format, it similar to case 2 study (Fixed format record) but DBF file has header, how can I tell SQL loader skip header.
    Thank you in advance

    Another option is to apply SQL operators to fields
    LOAD DATA
       INFILE *
       APPEND
    INTO TABLE emp
    FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY '"' (
       empno,
       ename,
       job,
       mgr,
       hiredate DATE(20) "DD-Month-YYYY",
       sal,
       comm,
       deptno CHAR TERMINATED BY ':',
       projno,
    loadseq "my_seq.nextval")This is a modified control file of Case Study 3 which originally demonstrated the use of the Sequence parameter

  • How to create a table from an existing table with new column

    Hi !
    Please help me.
    I want to create a table from an existing table with data and add two new column to the new table.
    What will be the syntax?

    craete table new_table as select a.*, 'somevalue' new_col1, 'somevalue'
    new_col2 from old_table a;Also there is a pitfall - newly created table will accept column type and precision from the select statement, so further you can be needed to modify columns
    if you want to have VARCHAR2 instead of CHAR for example:
    SQL> create table new_dept as select dept.*, 'New data' new_col from dept;
    Table created.
    SQL> desc new_dept
    Name                                      Null?    Type
    DEPTNO                                             NUMBER(2)
    DNAME                                              VARCHAR2(14)
    LOC                                                VARCHAR2(13)
    NEW_COL                                            CHAR(8)
    SQL> alter table new_dept modify (new_col varchar2(8));
    Table altered.
    SQL> desc new_dept
    Name                                      Null?    Type
    DEPTNO                                             NUMBER(2)
    DNAME                                              VARCHAR2(14)
    LOC                                                VARCHAR2(13)
    NEW_COL                                            VARCHAR2(8)Rgds.
    Didn't see michael's post - it reflects the fix for this problem using CAST.
    Message was edited by:
    dnikiforov

  • HELP: SQL*LOADER AND Ref Column

    Hallo,
    I have already posted and I really need help and don't come further with this
    I have the following problem. I have 2 tables which I created the following way:
    CREATE TYPE gemark_schluessel_t AS OBJECT(
    gemark_id NUMBER(8),
    gemark_schl NUMBER(4),
    gemark_name VARCHAR2(45)
    CREATE TABLE gemark_schluessel_tab OF gemark_schluessel_t(
    constraint pk_gemark PRIMARY KEY(gemark_id)
    CREATE TYPE flurstueck_t AS OBJECT(
    flst_id NUMBER(8),
    flst_nr_zaehler NUMBER(4),
    flst_nr_nenner NUMBER(4),
    zusatz VARCHAR2(2),
    flur_nr NUMBER(2),
    gemark_schluessel REF gemark_schluessel_t,
    flaeche SDO_GEOMETRY
    CREATE TABLE flurstuecke_tab OF flurstueck_t(
    constraint pk_flst PRIMARY KEY(flst_id),
    constraint uq_flst UNIQUE(flst_nr_zaehler,flst_nr_nenner,zusatz,flur_nr),
    flst_nr_zaehler NOT NULL,
    flur_nr NOT NULL,
    gemark_schluessel REFERENCES gemark_schluessel_tab
    Now I have data in the gemark_schluessel_tab which looks like this (a sample):
    1 101 Borna
    2 102 Draisdorf
    Now I wanna load data in my flurstuecke_tab with SQL*Loader and there I have problems with my ref column gemark_schluessel.
    One data record looks like this in my file (it is without geometry)
    1|97|7||1|1|
    If I wanna load my data record, it does not work. The reference (the system generated OID) should be taken from gemark_schluessel_tab.
    LOAD DATA
    INFILE *
    TRUNCATE
    CONTINUEIF NEXT(1:1) = '#'
    INTO TABLE FLURSTUECKE_TAB
    FIELDS TERMINATED BY '|'
    TRAILING NULLCOLS (
    flst_id,
    flst_nr_zaehler,
    flst_nr_nenner,
    zusatz,
    flur_nr,
    gemark_schluessel REF(CONSTANT 'GEMARK_SCHLUESSEL_TAB',GEMARK_ID),
    gemark_id FILLER
    BEGINDATA
    1|97|7||1|1|
    Is there a error I made?
    Thanks in advance
    Tig

    multiple duplicate threads:
    to call an oracle procedure and sql loader in an unix script
    Re: Can some one help he sql loader issue.

  • SQL*Loader with multiple files

    Gurus,
    I search the documentation and this forum and haven't found a solution to my issue yet...
    I am not expert of SQL*Loader. I have used SQL*Loader to copy from one file to a table many times. But I have not copied multiple files into one table especially with different names.
    More specifically....
    I need to load data from multiple files into a table. But the file names will be different each time. A file will be created every hour. The file name will consist of the root file name appended by a time stamp. For example, a file created on 10/07/2010 at 2:15 P.M. would be filea100720101415.txt while a file created on 10/08/2010 at 8:15 A.M. would be filea100820100815.txt. All the files will be in one directory.How can I load the data from the files using SQL*Loader?
    My database: Oracle 10g Release 2
    Operating System: Windows 2003 Server
    Please assist.
    Robert

    sect55 wrote:
    Gurus,
    I search the documentation and this forum and haven't found a solution to my issue yet...
    I am not expert of SQL*Loader. I have used SQL*Loader to copy from one file to a table many times. But I have not copied multiple files into one table especially with different names.
    More specifically....
    I need to load data from multiple files into a table. But the file names will be different each time. A file will be created every hour. The file name will consist of the root file name appended by a time stamp. For example, a file created on 10/07/2010 at 2:15 P.M. would be filea100720101415.txt while a file created on 10/08/2010 at 8:15 A.M. would be filea100820100815.txt. All the files will be in one directory.How can I load the data from the files using SQL*Loader?
    My database: Oracle 10g Release 2
    Operating System: Windows 2003 Server
    Please assist.
    RobertToo bad this isn't in *nix, where you get a powerful shell scripting capability. 
    That said, here is the core of the solution .... you will also need a way to identify files that have been processed vs. new ones. Maybe rename them, maybe move them. But with this sample you can see the basics. From there it is really an issue of DOS scripting, which would better be found by googling around a bit.
    cd c:\loadfiles
    FOR %%datfile IN (*.txt) DO SQLLDR CONTROL=sample.ctl, LOG=sample.log, BAD=baz.bad, DATA=%%datfileTry googling "dos scripting language". You'll find lots of tutorials and ideas on "advanced" (well, as advanced as DOS gets) techniques to solve your problem.
    Edited by: EdStevens on Dec 1, 2010 5:03 PM

  • SQL*Loader with ZONED EXTERNAL in a delimited file

    I have a text file delimited with '|' and numeric data with trailing signs, e.g somedata|12.00-|13.01|42.01-
    My table columns are defined as number(9,2) and I defined the datatype in the control file as zoned external. However, I get the dreaded ORA-01722: invalid number error.
    Does anyone have any suggestions?

    As Bravid says, you can't do that from within SQL*Loader, unless the control files are dynamically generated by a script and the filename included as the default value for that particular column as a hardcoded literal.
    It's easier if you use external tables as the table definition contains the "location" which is the list of filenames it is accessing, and the value can be queried as well as being dynamically changed (though if you're dynamically changing it, then you'll programatically know the filename anyway. hint hint!)
    ;)

  • SQL Loader with date formatting

    Hi,
    I'm trying to get sql loader to insert a date into a column. After much browsing, reading trial and error I still get an array of errors.
    I'm using oracle XE
    my control file looks like this
    LOAD DATA
    INFILE 'posmeters/meters.csv'
    INTO TABLE position_meters
    FIELDS terminated by ","
    ID CONSTANT '0',
    POSITION_ID,
    DATETIME DATE "DD/MM/YYYY HH24:MI:SS",
    CASH_IN,
    CASH_OUT,
    NOTES_IN,
    CHANGE_OUT,
    WINNINGS,
    VTP,
    REFILL,
    TOKEN_IN,
    TOKEN_OUT,
    ELEC_PAY,
    ELEC_CREDIT,
    REMOTE_PAY,
    REMOTE_CREDIT,
    INSERT_TS EXPRESSION "TO_CHAR(SYSDATE, 'DD/MM/YYYY HH24:MI:SS')",
    FIFTY_PND,
    TWENTY_PND,
    TEN_PND,
    FIVE_PND,
    TWO_PND,
    ONE_PND,
    FIFTY_P,
    TWENTY_P,
    TEN_P,
    FIVE_P
    It is the DATETIME field which gives me grief. I have a test data file that looks like this
    0,1010,29/09/2011 10:23:24,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24
    and my table is defined as follows
    ID NUMBER NOT NULL,
    POSITION_ID NUMBER,
    DATETIME TIMESTAMP(6) DEFAULT localTIMESTAMP NOT NULL,
    CASH_IN NUMBER,
    CASH_OUT NUMBER,
    NOTES_IN NUMBER,
    CHANGE_OUT NUMBER,
    WINNINGS NUMBER,
    VTP NUMBER,
    REFILL NUMBER,
    TOKEN_IN NUMBER DEFAULT (0) NOT NULL,
    TOKEN_OUT NUMBER DEFAULT (0) NOT NULL,
    ELEC_PAY NUMBER DEFAULT (0) NOT NULL,
    ELEC_CREDIT NUMBER DEFAULT (0) NOT NULL,
    REMOTE_PAY NUMBER DEFAULT (0) NOT NULL,
    REMOTE_CREDIT NUMBER DEFAULT (0) NOT NULL,
    INSERT_TS TIMESTAMP(6) DEFAULT (localtimestamp) NOT NULL,
    FIFTY_PND NUMBER DEFAULT 0,
    TWENTY_PND NUMBER DEFAULT 0,
    TEN_PND NUMBER DEFAULT 0,
    FIVE_PND NUMBER DEFAULT 0,
    TWO_PND NUMBER DEFAULT 0,
    ONE_PND NUMBER DEFAULT 0,
    FIFTY_P NUMBER DEFAULT 0,
    TWENTY_P NUMBER DEFAULT 0,
    TEN_P NUMBER DEFAULT 0,
    FIVE_P NUMBER DEFAULT 0
    I have tried defining the control file with
    DATETIME DATE "DD/MM/YYYY HH24:MI:SS",
    DATETIME EXPRESSION "TO_DATE(:DATETIME, 'DD/MM/YYYY HH24:MI:SS')",
    DATETIME EXPRESSION "TO_TIMESTAMP(:DATETIME, 'DD/MM/YYYY HH24:MI:SS')",
    I get errors such as
    Record 1: Rejected - Error on table "SITE_MAIN"."POSITION_METERS", column DATETIME.
    ORA-01861: literal does not match format string
    SQL*Loader-291: Invalid bind variable DATETIME in SQL string for column DATETIME.
    any help would greatfully appreciated.

    It seems that the problem was caused by the constant at the beginning of the record and had nothing to do with date formats.
    My control file now looks like this
    LOAD DATA
    INFILE 'posmeters/meters.csv'
    APPEND INTO TABLE position_meters
    FIELDS terminated by ","
    POSITION_ID          ,
    DATETIME      date "DD/MM/YYYY HH24:MI:SS",
    CASH_IN          ,
    CASH_OUT          ,
    NOTES_IN          ,
    CHANGE_OUT          ,
    WINNINGS          ,
    VTP               ,
    REFILL          ,
    TOKEN_IN          ,
    TOKEN_OUT          ,
    ELEC_PAY          ,
    ELEC_CREDIT          ,
    REMOTE_PAY          ,
    REMOTE_CREDIT     ,
    INSERT_TS      "TO_TIMESTAMP(SYSDATE, 'DD/MM/YYYY HH24:MI:SS')",
    FIFTY_PND          ,
    TWENTY_PND          ,
    TEN_PND          ,
    FIVE_PND          ,
    TWO_PND          ,
    ONE_PND          ,
    FIFTY_P          ,
    TWENTY_P          ,
    TEN_P          ,
    FIVE_P          
    all is good :o)

  • Problems using SQL*Loader with Oracle SQL Developer

    I have been using TOAD and able to import large (milllions of rows of data) in various file formats into a table in an Oracle database. My company recently decided not to renew any more TOAD licenses and go with Oracle SQL Developer. The Oracle database is on a corporate server and I access the database via Oracle client locally on my machine. Oracle SQL Developer and TOAD are local on my desktop and connected through TNSnames using the Windows XP platform. I have no issues with using SQL*Loader via the import wizard in TOAD to import the data in these large files into an Oracle table and producing a log file. Loading the same files via SQL*Loader in SQL Developer, freezes up my machine and I cannot get it to produce a log file. Please help!

    I am using SQL Developer version 3.0.04. Yes, I have tried it with a smaller file with no success. What is odd is that the log file is not even created. What is created is a .bat file a control file and a .sh file but no log file. The steps that I take:
    1.Right click on the table I want to import to or go to actions
    2. Import Data
    3. Find file to import
    4. Data Preview - All fields entered according to file
    5. Import Method - SQL Loader utility
    6. Column Definitions - Mapped
    7. Options - Directory of files set
    8. Finish
    With the above steps I was not able to import 255 rows of data. No log file was produced so I don't know why it is failing.
    thanks.
    Edited by: user3261987 on Apr 16, 2012 1:23 PM

  • SQL Loader input derived column

    Hi,
    I am running SQL Loader and I have two columns in my source file I am loading along with LoadDate and the name of the source file. my loader.ctl is below:
    load data
    infile 'c:\Reports\Test20070619.txt'
    APPEND
    into table MikeTest2
    fields terminated by "," optionally enclosed by '"'
    (OrderNumber,SKU,LoadDate sysdate,SourceFile "Test20070619.txt")
    How would I add the SourceFile Field value Test20070619.txt? I can get the LoadDate to load with sysdate. Any thoughts.
    Any info would be greatly appreciated.
    Thanks,
    Mike

    (OrderNumber,
    SKU,
    LoadDate sysdate,
    SourceFile "Test20070619.txt")If I understood your question correct:
    You can do this: Create a variable for the filename and use that variable:
    in a shell program:
    cat <<EOF! > $ctl_file
    LOAD DATA
    INFILE '$in_file'
    BADFILE '$HOME/logs/$bad_file'
    DISCARDFILE '$HOME/logs/$disc_file'
    (OrderNumber,
    SKU,
    LoadDate sysdate,
    SourceFile CONSTANT "$in_filename"
    )

  • SQL Loader - BLOB & LONG COLUMNS

    I have a table with 500 rows
    200 out of these rows need to be exported from one database to another database.
    These rows have long and blob columns with values. The long columns COULD contain all sorts of special characters.
    How can this be achieved with SQL Loader? Is there any other tool that can be used to get this done?
    Any help will be appreciated.

    Hello,
    What's your oracle version? As satish mentioned you can use datapump for load and unload. Here is an additional way of loading lob data
    To load data upto 32k, you can use varchar2(32656) but its not a good idea to load clob in that manner because it's very inconsistent as length can vary resulting in string literal too long. So you have 2 choices now, first you have to use either procedure or anonymous block to load clob data
    First Method -- I loaded alert.log successfully and you can imagine how big this file can be (5MB  (upto 4GB) in my test case)_
    CREATE OR REPLACE DIRECTORY DIR AS '/myapth/logs';
    DECLARE
       clob_data   CLOB;
       clob_file   BFILE;
    BEGIN
       INSERT INTO t1clob
       VALUES (EMPTY_CLOB ())
       RETURNING clob_text INTO clob_data;
       clob_file   := BFILENAME ('DIR', 'wwalert_dss.log');
       DBMS_LOB.fileopen (clob_file);
       DBMS_LOB.loadfromfile (clob_data,
                              clob_file,
                              DBMS_LOB.getlength (clob_file)
       DBMS_LOB.fileclose (clob_file);
       COMMIT;
    END;
    Second Method: Use of Sqlldr_
    LOAD DATA
    INFILE alert.log "STR '|\n'"
    REPLACE INTO  table t1clob
       clob_text char(30000000)
    )Hope this helps.
    Regards

  • SQL Help: Derive "new" columns based on condition

    Hello all,
    Can someone please help me with this ? I am trying to achieve this in a SQL ( not PL/SQL), if it can be done in two different steps, even that is fine too...
    Thanks in advance,
    Chandu
    SELECT * FROM
    SELECT 2765 BTCH_ID,'payroll' BTCH_NM,'payroll~EUR~EUR~DE'NEW_BTCH_NM,'1234'TMPLT_ID FROM DUAL
    UNION
    SELECT 2765,'payroll','payroll~USD~USD~US','1235' FROM DUAL
    UNION
    SELECT 2765,'payroll','payroll~USD~USD~US','1236' FROM DUAL
    UNION
    SELECT 2765,'payroll','payroll~GBP~GBP~GB','1237' FROM DUAL
    UNION
    SELECT 2766,'SALARY','SALARY~USD~USD~US','1238' FROM DUAL
    UNION
    SELECT 2766,'SALARY','SALARY~USD~USD~US','1239' FROM DUAL
    ) T_BATCH;For a "Batch-id" there exists multiple Transactions which are denoted by ( cr_crncy_cd , dr_crncy_cd , recvr_cntry_cd), and "NEW_BTCH_NM" column is basically a concatenation of "BTCH_NM" + above 3 columns ( with a ~)
    I am trying to derive two new columns 'SEQ' & 'Output_Batch_name'
    SEQ column:
    For every batch_id, the first row will be assigned by sequence.nextval.
        For all transactions within BTCH_ID,
                       all the rows with same NEW_BTCH_NM, share the same sequence number
                        if different, then SEQ.nextval for all distinct rows
    Output_BTCH_NM:
       for a given batch_id,
             if the NEW_BTCH_NM is the same for all transactions ( batch_id 2766 in the below example) , 
                             then Output_BTCH_NM = BTCH_NM should be marked for All transactions which belong to this Batch_id,
            Else
                Output_BTCH_NM = New_BTCH_NM
         END if
    Expected OUTPUT
    *BTCH_ID     BTCH_NM             NEW_BTCH_NM          TMPLT_ID     SEQ         Output_BTCH_NM*
    2765       payroll                payroll~EUR~EUR~DE     1234         1          payroll~EUR~EUR~DE
    2765       payroll                payroll~GBP~GBP~GB     1237         2          payroll~GBP~GBP~GB
    2765       payroll                payroll~USD~USD~US     1235         3          payroll~USD~USD~US
    2765       payroll                payroll~USD~USD~US     1236         3          payroll~USD~USD~US
    2766       SALARY                SALARY~USD~USD~US     1238         4          SALARY
    2766       SALARY                SALARY~USD~USD~US     1239         4          SALARYEdited by: user10711957 on Sep 25, 2010 4:37 PM

    Can someone please help me with this ? I am trying to achieve this in a SQL ( not PL/SQL), if it can be done in two different steps, even that is fine too...
    Thanks in advance,
    Chandu
    SELECT * FROM
    SELECT 2765 BTCH_ID,'payroll' BTCH_NM,'payroll~EUR~EUR~DE'NEW_BTCH_NM,'1234'TMPLT_ID FROM DUAL
    UNION
    SELECT 2765,'payroll','payroll~USD~USD~US','1235' FROM DUAL
    UNION
    SELECT 2765,'payroll','payroll~USD~USD~US','1236' FROM DUAL
    UNION
    SELECT 2765,'payroll','payroll~GBP~GBP~GB','1237' FROM DUAL
    UNION
    SELECT 2766,'SALARY','SALARY~USD~USD~US','1238' FROM DUAL
    UNION
    SELECT 2766,'SALARY','SALARY~USD~USD~US','1239' FROM DUAL
    ) T_BATCH;For a "Batch-id" there exists multiple Transactions which are denoted by ( cr_crncy_cd , dr_crncy_cd , recvr_cntry_cd), and "NEW_BTCH_NM" column is basically a concatenation of "BTCH_NM" + above 3 columns ( with a ~)
    I am trying to derive two new columns 'SEQ' & 'Output_Batch_name'
    SEQ column:
    For every batch_id, the first row will be assigned by sequence.nextval.
        For all transactions within BTCH_ID,
                       all the rows with same NEW_BTCH_NM, share the same sequence number
                        if different, then SEQ.nextval for all distinct rows
    Output_BTCH_NM:
       for a given batch_id,
             if the NEW_BTCH_NM is the same for all transactions ( batch_id 2766 in the below example) , 
                             then Output_BTCH_NM = BTCH_NM should be marked for All transactions which belong to this Batch_id,
            Else
                Output_BTCH_NM = New_BTCH_NM
         END if
    Expected OUTPUT
    *BTCH_ID     BTCH_NM             NEW_BTCH_NM          TMPLT_ID     SEQ         Output_BTCH_NM*
    2765       payroll                payroll~EUR~EUR~DE     1234         1          payroll~EUR~EUR~DE
    2765       payroll                payroll~GBP~GBP~GB     1237         2          payroll~GBP~GBP~GB
    2765       payroll                payroll~USD~USD~US     1235         3          payroll~USD~USD~US
    2765       payroll                payroll~USD~USD~US     1236         3          payroll~USD~USD~US
    2766       SALARY                SALARY~USD~USD~US     1238         4          SALARY
    2766       SALARY                SALARY~USD~USD~US     1239         4          SALARY

Maybe you are looking for

  • Importing old Movie from imovie in 08

    I can't use the share menu in 08 because it's dimmed. I imported an old imovie. I there's nothing in the project library, but the event library has all the clips. I can't drag them anywhere either. Having a hard time getting started with this. Thanks

  • Itunes accounts

    I have got to find someone who can explain how to best set up an itunes mess. We have one account for 1)imac 4)ipods 1)itouch 1)ipad and 1)MacBook Pro. It seemed like a good idea to have all the music in one place so that everyone could share as thei

  • I have bought un-useful app which is an image converter app. It did not mention unsupported formats can I get my money back?

    Dear Apple support team I have just bought an application, it is an image converter, but it did not mention that it doesn't support a specified image formats. When I bought it I could not get any use of it because it does not dupport NTF format. Can

  • Connected iPod to my laptop, 4,500 songs deleted

    I used several different apple USB cords and they all recognize my phone, but not my iPod... It just charges and yesterday I plugged it in to add more songs, and EVERYTHING was wiped out.. I plug my iPod into my laptop and its charging but no iPod ic

  • Time machine multiple backup drives question

    Time machine to backup to my 2TB MyBook drive.  I wanted a second backup on a portable 1TB, so in time machine settings, I selected the 1TB drive, and then clicked the "Replace" button, instead of the "Use both" button.  Currently the 1TB drive is ba