Sql*loader - load data in table with multiple condition

Hi,
I have oracle 9i on Sun sloaris and i need to load data in one of oracle table using sql*loader with conditional column data.
My table is like:
Load_table
col1 varchar2(10),
col2 varchar2(10),
col3 varchar2(10),
Now i have to load data like:
If col2 = US1 then col3 = 'AA'
If col2 = US2 then col3 = 'BB'
If col2 = US3 then col3 = 'CC'
How can i load this data in table using sql*loader?
Thanks,
Pora

Hi
it is a half-solution.
You have to:
1. open file
2. take a line
3. split the line into values (using substring to)
4. check condition (01 or 02)
5. do a proper insertion
Good Luck,
Przemek
DECLARE
v_dir VARCHAR2(50) := 'd:/tmp/'; --directory where file is placed
v_file VARCHAR2(50) := 'test.txt'; -- file name
v_fhandle UTL_FILE.FILE_TYPE; ---file handler
v_fline VARCHAR2(906); --file line
v_check VARCHAR2(50);
BEGIN
v_fhandle := UTL_FILE.FOPEN(v_dir, v_file, 'R'); --open file for read only
LOOP -- in the loop
UTL_FILE.GET_LINE( v_fhandle , v_fline); -- get line by line from file
if (substr(v_fline,17,2) = '01') then --check the value
INSERT INTO ... -- Time_in
else
INSERT INTO ... -- Time_out
end if;
END LOOP;
EXCEPTION
WHEN NO_DATA_FOUND
THEN UTL_FILE.FCLOSE( v_fhandle );
END;

Similar Messages

  • 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

  • Not able to load data in tables with correct way

    Hi
    i made one trigger to load data in view and tables.
    CODE FOR TRIGGER>>>>
    Object Details Code Errors SQL
    CREATE OR REPLACE TRIGGER "WELL_GENERATOR_TRIGGER_1"
    INSTEAD OF INSERT ON VIEW_WELL_GENERATOR_FORM
    FOR EACH ROW
    DECLARE
    rowcnt number;
    BEGIN
    INSERT INTO facility (FAC_PK) VALUES (:NEW.FAC_PK);
    SELECT COUNT(*) INTO rowcnt FROM WELL WHERE WEL_PK = :NEW.WEL_PK;
    IF rowcnt = 0 THEN
    INSERT INTO WELL (WEL_PK,SITE,FAC_FK) VALUES(:NEW.WEL_PK,:NEW.SITE,:NEW.FAC_PK);
    ELSE
    UPDATE WELL SET WELL.SITE = :NEW.SITE,
    WELL.FAC_FK = :NEW.FAC_PK
    WHERE WELL.WEL_PK = :NEW.WEL_PK;
    END IF;
    SELECT COUNT(*) INTO rowcnt FROM WELL_STATUS WHERE WELL_STATUS.STA_PK = :NEW.STA_PK;
    IF rowcnt = 0 THEN
    INSERT INTO WELL_STATUS (WELL_TYPE, WELL_TYPE_DATE, OPER_STATUS, CLASS,WEL_FK)
    VALUES(:NEW.WELL_TYPE, :NEW.WELL_TYPE_DATE, :NEW.OPER_STATUS, :NEW.CLASS,:NEW.WEL_PK);
    ELSE
    UPDATE WELL_STATUS SET WELL_STATUS.WELL_TYPE = :NEW.WELL_TYPE,
    WELL_STATUS.WELL_TYPE_DATE = :NEW.WELL_TYPE_DATE,
    WELL_STATUS.OPER_STATUS = :NEW.OPER_STATUS,
    WELL_STATUS.CLASS = :NEW.CLASS,
    WELL_STATUS.WEL_FK = :NEW.WEL_PK
    WHERE STA_PK = :NEW.STA_PK;
    END IF;
    SELECT COUNT(*) INTO rowcnt FROM PERMIT WHERE PERMIT.PER_PK = :NEW.PER_PK;
    IF rowcnt = 0 THEN
    INSERT INTO PERMIT (AUT_STATUS,WEL_FK) VALUES (:NEW.AUT_STATUS,:NEW.WEL_PK);
    ELSE
    UPDATE PERMIT SET PERMIT.AUT_STATUS = :NEW.AUT_STATUS,
    PERMIT.WEL_FK = :NEW.WEL_PK
    WHERE PERMIT.PER_PK = :NEW.PER_PK;
    END IF;Now But still i am not getting result which i want.Like in WELL_STATUS table i could nt able to insert the value (WEL_FK) from (WEL_PK).And In PERMIT table column (WEL_FK) still i could nt able to insert the value (WEL_PK).
    Now WEL_PK value autogenerate from the SEQ same with STA_PK and PER_PK.But instead of taking value from seq STA_PK take the value from WEL_PK (dnt know why ? But in data its shows me Same value WEL_PK and STA_PK).Same thing With PER_PK.
    so where i am wrong ? i really need your help.
    workspace:PRACTISE
    UN:[email protected]
    PW:testing
    Application:     39289 - TESTTING
    Thanks
    Edited by: vijaya45 on Jul 13, 2009 9:44 PM
    Edited by: vijaya45 on Jul 14, 2009 12:48 AM

    Hello vijaya45,
    Not sure if this will help, but I noticed you currently have a WELL_GENERATOR_TRIGGER_1 and a WELL_GENERATOR_TRIGGER_2, and "1" is disabled but "2" is enabled. Which one is supposed to be running at this point?
    John

  • Loading millions of rows using SQL*loader to a table with constraints

    I have a table with constraints and I need to load millions of rows in it using SQL*Loader.
    What is the best way to do this, means what SQL*Loader options to use, for getting the best loading performance and how to deal with constraints?
    Regards

    - check if your table has check constraints (like column not null)
    if you trust the data in the file you have to load you can disable this constrainst and after the loader enable this constrainst.
    - Check if you can modify the table and place it in nologging mode (generate less redo but ONLY is SOME Conditions)
    Hope it helps
    Rui Madaleno

  • 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

  • Deleting data from another table with multiple conditions

    Hi frnds
    I need to delete some data from a table based on multiple condition I tried following sql but its deleteing some rows which is not meeting the criteria which is really dangerours. When i trying = operator it returns ORa- 01427 single -row subquery returns more than one row
    delete from GL_TXNS
    where TRN_DT in (Select trn_Dt from GL_MAT)
    and BR in (select ac_branch from GL_MAT)
    and CODE in (select CODE T from GL_MAT)
    and (lcy_amt in (select lcy_amt from GL_MAT) or
    fcy_amt in(select fcy_amt from GL_MAT)
    rgds
    ramya

    My answer is the same as Avinash's but I will explain a little bit more.
    ORa- 01427 single -row subquery returns more than one rowmeans that you have a subquery that Oracle is expecting one value from that is returning multiple values. In your case you need one value for the equijoin ("=") and you are getting more than one value back. The error happens even if all the values are the same - multiple values being returned will cause the error.
    The solution is to either allow multiple values to be returned (say, use the IN condition istead of "=") or only return one value if possible (say, forcing one value by using DISTINCT, GROUP BY, or a WHERE clause condition of ROWNUM=1) - but these workarounds must be checked carefully to make sure they work correctkly

  • 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

  • LookUp to the same table with multiple conditions

    Hi,
    I nead to do a lookup to the same table in the flow but with diffrent quieres, each query contains it's own 'where'.
    Can I do it somehow in one look up or do I have to use a few ?
    select a from table where a=1
    select b from table where c=3
    Thanks

    Hi,
      Using multiple lookups will be a cleaner approach. If you are using multiple lookups on the same table consider using Cache transform. Refer the below link for details on Cache transform
    Lookup and Cache Transforms in SQL Server Integration Services
    Alternatively if you want to go ahead with single look up , you may have to modify the SQL statement in the Lookup accordingly to return the proper value. In you case it may be
    select a,b from table where a=1 or c=3
    Note : Consider the above as a pseudo code. This needs to be tested and applied based on your requirement.
    Best Regards Sorna

  • Query multiple values from tables with multiple conditions

    I'm trying to display the addresses from an employee record. There are two tables: employees and emp_addresses. There can be any number of addresses which is defined by the address type.
    What I want to do is get all the employees and all of the addresses for that employee in the same result.
    Addresses table:
    emp_id
    address1
    address2
    address3
    city
    state
    zip
    type (either H for 'home' or W for 'work')
    I would like the result set to be:
    emp_id | home_address1 | home_city | work_address1 | work_city
    Do I have to use a join? I'm not sure how to go about it.

    Hi,
    user9179751 wrote:
    I'm trying to display the addresses from an employee record. There are two tables: employees and emp_addresses. There can be any number of addresses which is defined by the address typeIf there can be any number of addresses, and you want to show all of them, then you probably need String Aggregation . See this page for different ways to do it:
    http://www.oracle-base.com/articles/10g/StringAggregationTechniques.php
    A related topic, that usually works better with a known number of columns, is Pivoting . See these links:
    SQL and PL/SQL FAQ
    There are ways to make pivoting work with a variable number of columns. See this thread:
    Re: Report count and sum from many rows into many columns
    What exactly are your requirements? Do you rally need separate columns for each address, or is it okay to have one big VARCHAR2 column that's formatted so it looks like separate columns? If you really need separate columns, do you know an upper limit to how many (e.g., there will never be more than 5)?
    What I want to do is get all the employees and all of the addresses for that employee in the same result.
    Addresses table:
    emp_id
    address1
    address2
    address3
    city
    state
    zip
    type (either H for 'home' or W for 'work')
    I would like the result set to be:
    emp_id | home_address1 | home_city | work_address1 | work_cityWhenever yo have a question, post CREATE TABLE and INSERT statements for some sample data, and the exact results you want from that data. Showing the column names for the sample data isn;t nearly as helpful as shoiwing some actual data (with column names). Showing the header line that goes over the results isn't nearly as helpful as showing the actual results (with the header line).
    Always say which version of Oracle you're using. Sting aggreagation and pivoting techiniques have changed significantly in every version since Oracle 7.
    Do I have to use a join? I'm not sure how to go about it.Using a join, you could get one more address for every join, but since there could be any number of addresses, you'd need any number of joins, and that means dynamic SQL. Join probably isn't the best approach in this case.

  • Loading a flat table with duplicate rows in SQL server

    Hi,
    I'm trying to load a flat table with different levels that has duplicate rows. When I'm loading it from my source SQL server enviornment to target SQL server environment.. I can only load 63 rows out of the 1225 rows.. This is happenning because i had to define a primary key on the couple of columns..
    When I just try to load it without a primary key, I get an error that PK needs to be defined for load to happen..
    My table structure looks as follows -
    Lvl1 Lvl2 Lvl3 Lvl4 AccountID AccountDesc
    How do i load all rows of data in my target table using ODI?\
    Please help

    whirlpool wrote:
    Hi,
    I'm trying to load a flat table What is a flat table ? Are you talking about FACT table ?
    When I'm loading it from my source SQL server enviornment to target SQL server environment.. I can only load 63 rows out of the 1225 rows.. This is happenning because i had to define a primary key on the couple of columns..
    When I just try to load it without a primary key, I get an error that PK needs to be defined for load to happen..
    Which IKM is in use ? I can not remember an IKM which needs a PK . Incremental Update IKM needs a Update key which can be a PK or UK at database level or ODI level.
    My table structure looks as follows -
    Lvl1 Lvl2 Lvl3 Lvl4 AccountID AccountDesc
    How do i load all rows of data in my target table using ODI?\
    If you not bother about PK at target then you can go for SQL Control Append to load your target table.
    Thanks,
    Sutirtha

  • Create sql loader data file dynamically

    Hi,
    I want a sample program/approach which is used to create a sql loader data file.
    The program will read table name as i/p and will use
    select stmt will column list derived from user_tab_columns from data dictionary
    assuming multiple clob columns in the column list.
    Thanks
    Manoj

    I 'm writing clob and other columns to a sql loader dat file.
    Below sample code for writing clob column is giving file write error.
    How can I write multiple clobs to dat file so that control file will handle it correctly
    offset NUMBER := 1;
    chunk VARCHAR2(32000);
    chunk_size NUMBER := 32000;
    WHILE( offset < dbms_lob.getlength(l_rec_type.narrative) )
    LOOP
    chunk := dbms_lob.substr(l_rec_type.narrative, chunk_size, offset );
    utl_file.put( l_file_handle, chunk );
         utl_file.fflush(l_file_handle);
    offset := offset + chunk_size;
    END LOOP;
         utl_file.new_line(l_file_handle);

  • SQL *Loader and External Table

    Hi,
    Can anyone tell me the difference between SQL* Loader and External table?
    What are the conditions under we can use SQL * Loader and External Table.
    Thanx

    External tables are accessible from SQL, which generally simplifies life if the data files are physically located on the database server since you don't have to coordinate a call to an external SQL*Loader script with other PL/SQL processing. Under the covers, external tables are normally just invoking SQL*Loader.
    SQL*Loader is more appropriate if the data files are on a different server or if it is easier to call an executable rather than calling PL/SQL (i.e. if you have a batch file that runs on a server other than the database server that wants to FTP a data file from a FTP server and then load the data into Oracle).
    Justin

  • SQL Loader versus External Table

    If anyone has worked on external tables please let me know your views.

    user637544 wrote:
    for sqlldr i follow the following approach
    1. truncate table
    2. call sqlldr and load records in staging table
    3. check for bad records
    how do i tuncate, call external table and check bad records for external table.As part of the SQL*Loader control file you can tell it to truncate the table as part of the process before it loads in the data.
    The key differences between SQL*Loader and External Tables are:
    1. SQL*Loader is an external utility run from the o/s command line, whereas External tables are usable from within SQL and PL/SQL.
    2. SQL*Loader can only load data up into the database, whereas External tables can allow you to read files and write files (10g onwards)
    3. SQL*Loader has limited control on skipping rows etc. whereas External tables can be queried using SQL and has all the flexibility that SQL can offer.
    4. SQL*Loader requires connection information to the database, whereas External tables are already part of the database
    5. SQL*Loader can only change the source filename through dynamic o/s level scripts, whereas External tables can have the filename changed using an ALTER TABLE ... LOCATION ... command.
    If you want to truncate your staging table before loading it with data from the external table, then you will just have to do that as a seperate step, because the external table is not associated with other tables. Simply truncate the other table and then query the data from the external table into the staging table.
    External tables offer a lot more flexibility than using SQL*Loader.

  • Sql loader or external table

    Hi all good morning.
    can we write a stored procedure that loads a file into the table using sql loader?
    can Java call the above stored procedure?
    regards
    raj
    Edited by: user10887630 on Apr 23, 2009 6:18 AM

    Are you saying the files themselves can't be located on the server? or just that the process for loading the files can't be located on the server.
    If the files themselves cannot reside on the server then you won't be able to use SQL*Loader or External tables from within stored procedures. It would require some clever Java code type stuff to get across to a.n.other machine where the files are stored and get the data.
    Typically it is normal for such files to be located on the server. What reasons do the DBA's give for not wanting them there?
    DBA's say that application specific files cannot be maintained on the Database serverSo what are all the database data files then? They hold data from the applications. ;)

  • Select max date from a table with multiple records

    I need help writing an SQL to select max date from a table with multiple records.
    Here's the scenario. There are multiple SA_IDs repeated with various EFFDT (dates). I want to retrieve the most recent effective date so that the SA_ID is unique. Looks simple, but I can't figure this out. Please help.
    SA_ID CHAR_TYPE_CD EFFDT CHAR_VAL
    0000651005 BASE 15-AUG-07 YES
    0000651005 BASE 13-NOV-09 NO
    0010973671 BASE 20-MAR-08 YES
    0010973671 BASE 18-JUN-10 NO

    Hi,
    Welcome to the forum!
    Whenever you have a question, post a little sample data in a form that people can use to re-create the problem and test their ideas.
    For example:
    CREATE TABLE     table_x
    (     sa_id          NUMBER (10)
    ,     char_type     VARCHAR2 (10)
    ,     effdt          DATE
    ,     char_val     VARCHAR2 (10)
    INSERT INTO table_x (sa_id,  char_type, effdt,                          char_val)
         VALUES     (0000651005, 'BASE',    TO_DATE ('15-AUG-2007', 'DD-MON-YYYY'), 'YES');
    INSERT INTO table_x (sa_id,  char_type, effdt,                          char_val)
         VALUES     (0000651005, 'BASE',    TO_DATE ('13-NOV-2009', 'DD-MON-YYYY'), 'NO');
    INSERT INTO table_x (sa_id,  char_type, effdt,                          char_val)
         VALUES     (0010973671, 'BASE',    TO_DATE ('20-MAR-2008', 'DD-MON-YYYY'), 'YES');
    INSERT INTO table_x (sa_id,  char_type, effdt,                          char_val)
         VALUES     (0010973671, 'BASE',    TO_DATE ('18-JUN-2010', 'DD-MON-YYYY'), 'NO');
    COMMIT;Also, post the results that you want from that data. I'm not certain, but I think you want these results:
    `    SA_ID LAST_EFFD
        651005 13-NOV-09
      10973671 18-JUN-10That is, the latest effdt for each distinct sa_id.
    Here's how to get those results:
    SELECT    sa_id
    ,         MAX (effdt)    AS last_effdt
    FROM      table_x
    GROUP BY  sa_id
    ;

Maybe you are looking for

  • How to set up an HP6122 on home network with Win 7 laptop?

    HP6122 works when plugged into laptop USB port.  Can't get it to work when it's plugged into an XP computer on the same network.

  • Can no longer access epub books since iOS update

    Until recently I had a number of books and PDFs installed on my iPad that I accessed through iBooks.  During a recent iOS upgrade ALL of them were removed from my iPad, but were still available on iTunes.  I have been able to move all of the PDFs bac

  • Dynamic screen size in BDC

    Hi ppl, I have created a BDC program to upload certain data in a particular transaction which has a table control. This program will be called from devices having different screen sizes. In one of the devices, the table control of the transaction dis

  • Report Bursting in BIP

    I am new to BIP. We have a scheduled report that bursts different pdfs every week on friday. These pdfs are bursted to an ECM folder through WebDAV.This folder is static. But I have to burst the pdfs to a different new folder everyweek. Is there a wa

  • TOUCH_END event fired on all touch id when just one touch was release

    Hi I am developing a parking car game. I have a  strange problem. If i start touch on steeering and on gaz and then i release on of them , the TOUCH_END event is fired on both, and i still keep me finger stick to touch screen. Multitouch.inputMode=Mu