Shell Script Programming -- Loading data into table

Hello Gurus
I am using Oracle's sql*loader utility to load data into a table. Lately, I got an unlikely scenario where in I need to process the data file first before loading it into the table and where I need help from you guys.
Consider the following data line
"Emp", DOB, Gender, Subject
"1",01/01/1980,"M","Physics:01/05/2010"
"2",01/01/1981,"M","Chemistry:02/05/2010|Maths:02/06/2011"
"3",01/01/1982,"M","Maths:03/05/2010|Physics:06/07/2010|Chemistry:08/09/2011"
"4",01/01/1983,"M","Biology:09/09/2010|English:10/10/2010"Employee - 1 will get loaded as a single record in the table. But I need to put Subject value into two separate fields into table. i.e. Physics into one column and date - 01/05/2010 into separate column.
Here big problem starts
Employee - 2 Should get loaded as 2 records into the table. The first record should have Chemistry as subject and date as 02/05/2010 and the next record should have all other fields same except the subject should be Maths and date as 02/06/2011. The subjects are separated by a pipe "|" in the data file.
Similarly, Employee 3 should get loaded as 3 records. One as Maths, second as Physics and third as Chemistry along with their respective dates.
I hope I have made my problem clear to everyone.
I am looking to do something in shell scripting such that before finally running the sql*loader script, the above 4 employees have their records repeated as many times as their subject changes.
In summary 2 problems are described above.
1. To load subject and date into 2 separate fields in Oracle table at the time of load.
2. If their exists multiple subjects then a record is to be loaded that many times as there exists any changes in employee's subject.
Any help would be much appreciated.
Thanks.

Here are some comments. Perl can be a little cryptic but once you get used to it, it can be pretty powerful.
#!/usr/bin/perl -w
my $line_count = 0;
open FILE, "test_file" or die $!;
# Read each line from the file.
while (my $line = <FILE>) {
    # Print the header if it is the first line.
    if ($line_count == 0) {
        chomp($line);
        print $line . ", Date\n";
        ++$line_count;
        next;   
    # Get all the columns (as separated by ',' into an array)
    my @columns = split(',', $line);
    # Remove the newline from the fourth column.
    chomp($columns[3]); 
    # Read the fields (separated by pipe) from the fourth column into an array.
    my @subject_and_date = split('\|', $columns[3]);     
    # Loop for each subject and date.
    foreach my $sub_and_date (@subject_and_date) {
        # Print value of Emp, DOB, and Gender first.
        print $columns[0] . "," . $columns[1] . "," . $columns[2] . ",";
        # Remove all double quotes from the subject and date string.
        $sub_and_date =~ s/"//g;
        # Replace ':' with '","'
        $sub_and_date =~ s/:/","/;
        print '"' . $sub_and_date . '"' . "\n";       
    ++$line_count;
close FILE;

Similar Messages

  • FDMEE Import error "No periods were identified for loading data into table 'AIF_EBS_GL_BALANCES_STG'

    Hi,
    We are having trouble while importing one ledger 'GERMANY EUR GGAAP'. It works for Dec 2014 but while trying to import data for 2015 it gives an error.
    Import error shows " RuntimeError: No periods were identified for loading data into table 'AIF_EBS_GL_BALANCES_STG'."
    I tried all Knowledge docs from Oracle support but no luck. Please help us resolving this issue as its occurring in our Production system.
    I also checked all period settings under Data Management> Setup> Integration Setup > Global Mapping and Source Mapping and they all look correct.
    Also its only happening to one ledger rest all ledgers are working fine without any issues.
    Thanks

    Hi,
    there are some Support documents related to this issue.
    I would suggest you have a look to them.
    Regards

  • How can I load data into table with SQL*LOADER

    how can I load data into table with SQL*LOADER
    when column data length more than 255 bytes?
    when column exceed 255 ,data can not be insert into table by SQL*LOADER
    CREATE TABLE A (
    A VARCHAR2 ( 10 ) ,
    B VARCHAR2 ( 10 ) ,
    C VARCHAR2 ( 10 ) ,
    E VARCHAR2 ( 2000 ) );
    control file:
    load data
    append into table A
    fields terminated by X'09'
    (A , B , C , E )
    SQL*LOADER command:
    sqlldr test/test control=A_ctl.txt data=A.xls log=b.log
    datafile:
    column E is more than 255bytes
    1     1     1     1234567------(more than 255bytes)
    1     1     1     1234567------(more than 255bytes)
    1     1     1     1234567------(more than 255bytes)
    1     1     1     1234567------(more than 255bytes)
    1     1     1     1234567------(more than 255bytes)
    1     1     1     1234567------(more than 255bytes)
    1     1     1     1234567------(more than 255bytes)
    1     1     1     1234567------(more than 255bytes)

    Check this out.
    http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96652/ch06.htm#1006961

  • Loading Data into Table with Complex Transformations

    Hello Guys
    I am trying to load data into one of the Dimension table and it has quite a few Transformations and i created 6 temp tables
    1. It has 7 Columns , Gets 935 rows based on where condition
    2. It has 10 Columns , Gets 935 rows with but it has nulls in it i.e for column 1 there are 500 fields and columns 2 there are 300 etc ...
    3 , 4 , 5 , 6 all the same as the 2 table
    and at the end when i am trying to join all the temp tables with the Product_id into the target , which is in each temp table ...
    I am Getting Error Saying Not Obeying Primary key Constraints i.e unique values are not been inserting into the Product_id Column of Target Table and the Job is running for Hours
    and the main Problem comes at , some of the Columns have the same Product_id
    Please help me
    I have been Trying for 1 week and i am in Full pressure
    Thanks
    Sriks
    Edited by: Sriks on Oct 16, 2008 6:43 PM

    Hi,
    If you are creating a warehouse and product_key is ur PK then it should come only once and so u might have to think ur logic in getting the data. To get over the isue u can disable the constraint and load with out the cosntraint, but i would have u look at the logic and make sure u have only 1 product_key in the table.
    Regards
    Bharath

  • How to load data into table Using Script Task

    We have a directory/folder where we have a file. We need to insert the File Created Date , File Name , Extension into the database table of Sql server by using Script Task.
    So could you please suggest , how to frame the connection string , fetch the file details and insert the data into the database table using Script Task of SSIS 2008

    You can achieve it as follows using standard script task
    1. Add a ForEachLoop container to point to your directory to iterate though the files. Add a variable of type string inside loop to get file name of each file it iterates. Choose option Filename and extension. Add a variable to just store extension part
    (FileExtension), set EValuateAsExpression true for it and give expression as below
    SUBSTRING(@[User::FileName],FINDSTRING(@[User::FileName],".",1)+1,LEN(@[User::FileName]))
    2. Add a script task inside loop and pass filename variable as a read only variable to it. Crete a new variable to get creationdate and pass it as ReadWrite. Inside write code as below
    Public Sub Main()
    ' Add your code here
    Dim f As New System.IO.FileInfo(Dts.Variables("FileName").Value.ToString())
    Dts.Variables("FileCreatedDate").Value = f.CreationTime
    Dts.TaskResult = ScriptResults.Success
    End Sub
    3. Add a Exec SQL Task after Script task inside loop and give a query like below
    INSERT INTO TableName (FileName,CreatedDate,Extension)
    VALUES(?,?,?)
    and in parameter tab map the parameter placeholders 0,1 and 2 to @[User::FileName],@[User::FileCreatedDate] & @[User::FileExtension] variables
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Load data into Table

    I want to load certain columns from table1 into columns in another table (table2) which is similar to table1 but have some additional columns.
    I am aware of PL/SQL solution to doing this. But i need to do this using sql statement that is driven from Java.
    Important part is read data from table1, copy in another table (table2) and update status in table1 all these activities should be part of one transaction.

    use view if u know from which table which columb you want and call that view from java....and triggers are also usefull in that condition on running of that view trigger should do its work....actually it will be better if you can eloborate your problem.

  • Loading data into table with filename

    Hi All,
    I am new to ODI. I have a requirement to load of a flat file into oracle, along with the name of file in one column of the table. That means, if there are 10 rows of data from that file then the additional column 'FileName" of the table will have current file name written 10 times. Please suggest how this can be achieved. I am able to do half of it but file name is not populated.
    Thanks.

    Hi ,
    Probably what you can do is
    1. create a variable to read the file name . Refer http://odiexperts.com/?tag=file-variable-odi for creating such a variable.
    2. Now in your interface , target table column which holds the filename , use '#<variable created in step 1>'
    and specify it to be executed on target .
    It should do the trick .
    Thanks,
    Sutirtha

  • Loading data into two files

    Hi
    I have written sql loader script for loading data into two tables.
    Script is working ..But output is not coming properly.
    I want to load data into first table which lines are having first char 'R'.
    In the second table I have to load data which are related from the first line. Incase
    first line data is not properly (means discarded) then related second table data
    will not be load.
    But I am getting both rows.Though the first table record is discarded. Please find below
    the output.
    Any other solution also ....Ok..external tables..Utl_file.
    LOAD DATA
    infile "inputFileForRmaReceiptAcknowledgement.dat"
    BADFILE 'inputFileForRmaReceiptAcknowledgement.bad'
    DISCARDFILE 'inputFileForRmaReceiptAcknowledgement.dsc'
    APPEND
    INTO TABLE XXGW_RMA_HEDR_RCPTACK_TAB
       WHEN (01)='R'
          (  LINE_TYPE              POSITION(1:1) "substr(:Line_Type, 1)",
             RMA_ORDER_NO           POSITION(2:16)  CHAR,
             ACKNOWLEDGEMENT_NO     POSITION(17:31) CHAR,
             ACKNOWLEDGEMENT_DATE   POSITION(32:45) 
    "to_date(substr(:acknowledgement_date,3),'YYMMDDHH24MISS')",
             DETAIL_LINE_COUNT      POSITION(46:51) INTEGER EXTERNAL,
             FLAG                   CHAR)
    INTO TABLE XXGW_RMA_RCPT_ACKLDGMNT_TAB
       WHEN (01) = 'D'
          (  LINE_TYPE              POSITION(1:1) "substr(:Line_Type, 1)",
             RMA_ORDER_NO           POSITION(2:16)    CHAR,
             RMA_ORDER_LINE         POSITION(17:19)   INTEGER EXTERNAL,
             SERIAL_NUMBER          POSITION(20:49)   CHAR,
             SKU                    POSITION(50:63)   CHAR,
             QUANTITY               POSITION(64:69)   INTEGER EXTERNAL,
             WAREHOUSE_CODE         POSITION(70:71)   CHAR,
             WAYBILL_NUMBER         POSITION(72:121)  CHAR,
             COURIER                POSITION(122:146) CHAR,
             RETURN_DEALER_FLAG     POSITION(147:156) CHAR)
    inputFileForRmaReceiptAcknowledgement.dat
    R12345678901    2345456789123200   21111228241113000002  --- discarded record
    D12345678901    00159123687402 45678925803   00000102name                                  
    D12345678901    00159143687402 45678925603   00000102name                                  
    T000004Regards
    Ar

    Pl post details of OS and database versions.
    Create a foreign key constraint between the detail table and the master table. If the row fails to load into the master table, then the detail table rows will fail the foreign key constraint and will not load.
    http://docs.oracle.com/cd/E11882_01/server.112/e25789/datainte.htm#CNCPT1649
    HTH
    Srini

  • Can i use one interface to load data into 2 different tables

    Hi Folks,
    Can i use one interface to load data into 2 different tables(same schema or different schemas) from one source table with same structure ?
    Please give me advice
    Thanks
    Raj
    Edited by: user11410176 on Oct 21, 2009 9:55 AM

    Hi Lucky,
    Thanks for your reply,
    What iam trying is ...Iam trying to load the data from legacy tables(3) into oracle staging tables.But i need to load the same source data into two staging tables(these staging tables are in two different schemas)
    can i load this source data into two staging tables by using single standard interface(some business logic is there)
    If i can then give me some suggestion how to do that
    Thanks in advance
    Raj

  • Error while loading  data into External table from the flat files

    HI ,
    We have a data load in our project which feeds the oracle external tables with the data from the Flat Files(.bcp files) in unix.
    While loading the data, we are encountering the following error.
    Error occured (Error Code : -29913 and Error Message : ORA-29913: error in executing ODCIEXTTABLEOPEN callout
    ORA-29400: data cartridge error
    KUP-04063: un) while loading data into table_ext
    Please let us know what needs to be done in this case to solve this problem.
    Thanks,
    Kartheek

    Kartheek,
    I used Google (mine still works).... please check those links:
    http://oraclequirks.blogspot.com/2008/07/ora-29400-data-cartridge-error.html
    http://jonathanlewis.wordpress.com/2011/02/15/ora-29913/
    HTH,
    Thierry

  • How to  load data into user tables using DIAPIs?

    Hi,
    I have created an user table using UserTablesMD object.
    But I don't have know how to load data into this user table. I guess I have to use UserTable object for that. But I still don't know how to put some data in particular column.
    Can somebody please help me with this?
    I would appreciate if somebody can share their code in this regard.
    Thank you,
    Sudha

    You can try this code:
    Dim lRetCode As Long
    Dim userTable As SAPbobsCOM.UserTable
    userTable = pCompany.UserTables.Item("My_Table")
    'First row in the @My_Table table
    userTable.Code = "A1"
    userTable.Name = "A.1"
    userTable.UserFields.Fields.Item("U_1stF").Value = "First row value"
    userTable.Add()
    'Second row in the @My_Table table
    userTable.Code = "A2"
    userTable.Name = "A.2"
    userTable.UserFields.Fields.Item("U_1stF").Value = "Second row value"
    userTable.Add()
    This way I have added 2 lines in my table.
    Hope it helps
    Trinidad.

  • Using Import Man to load Data into Multi Value Fileds in a Qualified Table

    Hi there,
    When using the Import Manager, i can not use the "append" option to load data into my multi value field which is contained within my qualified table.
    Manually it works fine on Data manager, so the field has been set up correctly. Only problem is appending the data during Import Manager Load.
    Any reason why I do not have this option available during Field mapping in Import Manager. The selection options are shown but in gray.
    Would appreciate any sugestions.
    Chris Huggett

    Thanks Sowseel
    Its a good document but doesn't address my problem, maybe My problem isn't clear.
    The structure(part of) that I have currently is as follows.
    Main Table - Material
                           QFTable-  MNF PN
                               LUField - MNF Name(Qualifier Single Value)
                               LUField  - BU ID  (Non Qualifier Multi Value)
                               TField   - P/N- (Non Qualifier)
    I know how to load data to the main and qualified tables, but what I can not do, using Import Manger, is updating the  "LUField  - BU ID  (Non Qualifier Multi Value)" using the append functionality.
    Thanks
    Chris Huggett

  • Loading this xml data into tables

    Hello,
    I am having a problem loading this XML file into tables. The xml file structure is
    <FILE>
    <ACCESSION>
    some ids
    <INSTANCE>
    some data
    <VARIATION
    </VARIATION>
    <VARIATION>
    </VARIATION> variation gets repeated a number of times
    <ASSEMBLY>
    </ASSEMBLY>
    <ASSEMBLY>
    </ASSEMBLY> Assembly gets repeated a number of times.
    </INSTANCE>
    </ACCESSION>
    </FILE>
    I created a table which has the structure:
    create table accession(
    accession_id varchar2(20),
    Instance instance_type);
    create or replace type instance_type as object
    (method varchar2(20),
    class varchar2(20),
    source varchar2(20),
    num_char number(10),
    variation variation_type,
    assembly assembly_type)
    create or replace type variation_type as object
    (value varchar2(2),
    count number(10),
    frequency number(10),
    pop_id varchar2(10)
    Created a similiar type for assembly.
    When I load it, I could only store the first variation data but not the subsequent ones. Similarly for assembly I could only store the first data but not the subsequent ones.
    Could anyone let me know how I could store this data into tables? I have also included a sample XML file in this message.
    Thank You for your help.
    Rama.
    Here is the sample xml file.
    <?xml version="1.0" ?>
    - <FILE>
    - <ACCESSION>
    <ACCESSION_ID>accid1</ACCESSION_ID>
    - <INSTANCE>
    <METHOD>method1</METHOD>
    <CLASS>class1</CLASS>
    <SOURCE>source1</SOURCE>
    <NUM_CHAR>40</NUM_CHAR>
    - <VARIATION>
    <VALUE>G</VALUE>
    <COUNT>5</COUNT>
    <FREQUENCY>66</FREQUENCY>
    <POP1>pop1</POP1>
    <POP2>pop1</POP2>
    </VARIATION>
    <VARIATION>
    <VALUE>C</VALUE>
    <COUNT>2</COUNT>
    <FREQUENCY>33</FREQUENCY>
    <POP_ID1>pop2</POP_ID1>
    </VARIATION>
    - <ASSEMBLY>
    <ASSEMBLY_ID>1</ASSEMBLY_ID>
    <BEGIN>180</BEGIN>
    <END>180</END>
    <TYPE>2</TYPE>
    <ORI>-</ORI>
    <OFFSET>0</OFFSET>
    </ASSEMBLY>
    - <ASSEMBLY>
    <ASSEMBLY_ID>2</ASSEMBLY_ID>
    <BEGIN>235</BEGIN>
    <END>235</END>
    <TYPE>2</TYPE>
    <ORI>-</ORI>
    <OFFSET>0</OFFSET>
    </ASSEMBLY>
    </INSTANCE>
    </ACCESSION>
    </FILE>

    Hello,
    I could figure out how to load this XML file by using cast(multiset(
    So never mind.
    Thank You.
    Rama.

  • Loading data into existing table

    Hi I have tried to load data into a large table from a csv file but am not getting any success. I have this control file
    LOAD DATA
    INFILE 'Book1.xls'
    BADFILE 'p_sum_bad.txt'
    DISCARDFILE 'p_sum_dis.txt'
    APPEND
    INTO TABLE p_sum
    FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
    TRAILING NULLCOLS
    SUMMARY_LEVEL ,
    PERIOD_START_TIME ,
    BUSY_HOUR ,
    OMC ,
    INT_ID ,
    BTS_ID ,
    BTS_INT_ID ,
    CELL_GROUP ,
    HO_PERIOD_DURATION ,
    POWER_PERIOD_DURATION ,
    MSC_I_SUCC_HO ,
    MSC_I_TCH_TCH ,
    MSC_I_SDCCH_TCH ,
    MSC_I_SDCCH ,
    MSC_I_TCH_TCH_AT ,
    MSC_I_SDCCH_TCH_AT ,
    MSC_I_SDCCH_AT ,
    MSC_I_FAIL_LACK ,
    MSC_I_FAIL_CONN ,
    MSC_I_FAIL_BSS ,
    MSC_I_END_OF_HO ,
    MSC_O_SUCC_HO ,
    The data is:
    2     3-Nov-06               1000033     9     8092220          1440     1440     5411     5374     7     30     5941
    2     3-Nov-06               1000033     10     1392190          1440     1440     0     0     0     0     0
    2     3-Nov-06               2000413     3     2127446          1440     1440     80     80     0     0     83
    2     3-Nov-06               2000413     4     2021248          1140     1440     0     0     0     0     0
    2     3-Nov-06               2000413     5     2021252          1080     1440     1     1     0     0     1
    2     3-Nov-06               2000413     6     2130163          1440     1440     2200     2193     2     5     2224
    2     3-Nov-06               2000413     7     6205155          1020     1440     0     0     0     0     0
    2     3-Nov-06               2000413     8     6200768          900     1440     30     30     0     0     31
    2     3-Nov-06               2000413     10     2111877          1440     1440     0     0     0     0     0
    2     3-Nov-06               1000033     18     1076419          1440     1440     75     73     0     2     79
    2     3-Nov-06               1000033     19     8089060          1440     1440     0     0     0     0     0
    but when I try to load the data, I get:
    Column Name Position Len Term Encl Datatype
    SUMMARY_LEVEL FIRST * , O(") CHARACTER
    PERIOD_START_TIME NEXT * , O(") CHARACTER
    Record 51: Rejected - Error on table OMC.P_SUM_BTS_HO_POWER, column SUMMARY_LEVEL.
    ORA-01722: invalid number
    I believe the data being loaded has to be NUMBER. Can anyone adivse what do I need to change to load the data. Thanks

    Justin,
    Tried that, no luck:
    Number to load: ALL
    Number to skip: 0
    Errors allowed: 50
    Bind array: 64 rows, maximum of 256000 bytes
    Continuation: none specified
    Path used: Conventional
    Table P_SUM, loaded from every logical record.
    Insert option in effect for this table: APPEND
    TRAILING NULLCOLS option in effect
    Column Name Position Len Term Encl Datatype
    SUMMARY_LEVEL FIRST * WHT O(") CHARACTER
    PERIOD_START_TIME NEXT * WHT O(") CHARACTER
    BUSY_HOUR NEXT * WHT O(") CHARACTER
    OMC NEXT * WHT O(") CHARACTER
    INT_ID NEXT * WHT O(") CHARACTER
    BTS_ID NEXT * WHT O(") CHARACTER
    BTS_INT_ID NEXT * WHT O(") CHARACTER
    CELL_GROUP NEXT * WHT O(") CHARACTER
    Record 51: Rejected - Error on table OMC.P_SUM_BTS_HO_POWER, column SUMMARY_LEVEL.
    ORA-01722: invalid number
    Any other sugesstion

  • Loading data into a table

    I am loading data into a table I created which includes a column "Description" with a data type VARCHAR2(1000). When I go to load the data which is less than 1000 characters I receive the following error message:
    Record 38: Rejected - Error on table SSW_INPUTS, column DESCRIPTION.
    Field in data file exceeds maximum length
    I have increased the size of the column but that does not seem to fix the error. Does anyone know what this error means? Another thought is that I have created the "Description" column to large...which can't be true because I should receive the error when I create the table. Plus I already inputted data into a similar table with similar data and had no problems!
    Someone please help...
    Thank you,
    April.

    Note that I'm assuming Oracle8(i) behavior. Oracle9 may treat Unicode differently.
    Are you inserting Unicode data into the table? Declaring a variable as varchar2(1000) indicates that Oracle should reserve 1000 bytes for data. If you're inserting UTF-8 encoded data, each character may take up to 3 bytes to store. Thus, 334 characters of data could theoretically overflow a varchar2(1000) variable.
    Note that UTF-8 is designed so that the most commonly used characters are stored in 1 byte, less commonly used characters are stored in 2 bytes, and the remainder is stored in 3 bytes. On average, this will require less space than the more familiar UCS-2 encoding which stores every character as 2 bytes of data.
    Justin

Maybe you are looking for