Sql * loader/Utl_file

Hi all,
As i know that both the UTL_FILE package and SQL* Loader are used to Load the flat file data into Apps Table.
My question is
1) Which one is the Best Method to use.
2) Advantages and disadvantages by using UTL_FILE and SQL* LOADER ;
Thanks In Advance
Goutham Konduru

Triple posting
Diffrence b/w UTL_FILE package & SQL Loader
UTL_FILE package and SQL* Loader

Similar Messages

  • Sql loader utl_file & external table

    can any one let me know the differences between.
    1.sql loader
    2.utl_file
    3.external table
    Regards.
    Asif.

    To expand on Aron's answer....
    SQL*Loader - An operating system utility which uses control files (which you create) to load data files onto database tables.
    UTL_FILE - A database package which can be used for reading and writing files in any format you care to design programmatically.
    External Table - The latest thing which can be used instead of SQL*Loader. This is done from the database end, by creating a table as an external table and pointing it at the source file on the operating system. It also allows information similar to that put in the SQL*Loader control files to be specified against the table. By querying against the table you are in fact querying against the source file. There are some limitation compared to regular database tables such as there is no ability to write to the external table.
    ;)

  • Using SQL*Loader and UTL_FILE to load and unload large files(i.e PDF,DOCs)

    Problem : Load PDF or similiar files( stored at operating system) into an oracle table using SQl*Loader .
    and than Unload the files back from oracle tables to prevoius format.
    I 've used SQL*LOADER .... " sqlldr " command as :
    " sqlldr scott/[email protected] control=c:\sqlldr\control.ctl log=c:\any.txt "
    Control file is written as :
    LOAD DATA
    INFILE 'c:\sqlldr\r_sqlldr.txt'
    REPLACE
    INTO table r_sqlldr
    Fields terminated by ','
    id sequence (max,1) ,
    fname char(20),
    data LOBFILE(fname) terminated by EOF )
    It loads files ( Pdf, Image and more...) that are mentioned in file r_sqlldr.txt into oracle table r_sqlldr
    Text file ( used as source ) is written as :
    c:\kalam.pdf,
    c:\CTSlogo1.bmp
    c:\any1.txt
    after this load ....i used UTL_FILE to unload data and write procedure like ...
    CREATE OR REPLACE PROCEDURE R_UTL AS
    l_file UTL_FILE.FILE_TYPE;
    l_buffer RAW(32767);
    l_amount BINARY_INTEGER ;
    l_pos INTEGER := 1;
    l_blob BLOB;
    l_blob_len INTEGER;
    BEGIN
    SELECT data
    INTO l_blob
    FROM r_sqlldr
    where id= 1;
    l_blob_len := DBMS_LOB.GETLENGTH(l_blob);
    DBMS_OUTPUT.PUT_LINE('blob length : ' || l_blob_len);
    IF (l_blob_len < 32767) THEN
    l_amount :=l_blob_len;
    ELSE
    l_amount := 32767;
    END IF;
    DBMS_LOB.OPEN(l_blob, DBMS_LOB.LOB_READONLY);
    l_file := UTL_FILE.FOPEN('DBDIR1','Kalam_out.pdf','w', 32767);
    DBMS_OUTPUT.PUT_LINE('File opened');
    WHILE l_pos < l_blob_len LOOP
    DBMS_LOB.READ (l_blob, l_amount, l_pos, l_buffer);
    DBMS_OUTPUT.PUT_LINE('Blob read');
    l_pos := l_pos + l_amount;
    UTL_FILE.PUT_RAW(l_file, l_buffer, TRUE);
    DBMS_OUTPUT.PUT_LINE('writing to file');
    UTL_FILE.FFLUSH(l_file);
    UTL_FILE.NEW_LINE(l_file);
    END LOOP;
    UTL_FILE.FFLUSH(l_file);
    UTL_FILE.FCLOSE(l_file);
    DBMS_OUTPUT.PUT_LINE('File closed');
    DBMS_LOB.CLOSE(l_blob);
    EXCEPTION
    WHEN OTHERS THEN
    IF UTL_FILE.IS_OPEN(l_file) THEN
    UTL_FILE.FCLOSE(l_file);
    END IF;
    DBMS_OUTPUT.PUT_LINE('Its working at last');
    END R_UTL;
    This loads data from r_sqlldr table (BOLBS) to files on operating system ,,,
    -> Same procedure with minor changes is used to unload other similar files like Images and text files.
    In above example : Loading : 3 files 1) Kalam.pdf 2) CTSlogo1.bmp 3) any1.txt are loaded into oracle table r_sqlldr 's 3 rows respectively.
    file names into fname column and corresponding data into data ( BLOB) column.
    Unload : And than these files are loaded back into their previous format to operating system using UTL_FILE feature of oracle.
    so PROBLEM IS : Actual capacity (size ) of these files is getting unloaded back but with quality decreased. And PDF file doesnt even view its data. means size is almot equal to source file but data are lost when i open it.....
    and for images .... imgaes are getting loaded an unloaded but with colors changed ....
    Also features ( like FFLUSH ) of Oracle 've been used but it never worked
    ANY SUGGESTIONS OR aLTERNATE SOLUTION TO LOAD AND UNLOAD PDFs through Oracle ARE REQUESTED.
    ------------------------------------------------------------------------------------------------------------------------

    Thanks Justin ...for a quick response ...
    well ... i am loading data into BLOB only and using SQL*Loader ...
    I've never used dbms_lob.loadFromFile to do the loads ...
    i 've opend a file on network and than used dbms_lob.read and
    UTL_FILE.PUT_RAW to read and write data into target file.
    actually ...my process is working fine with text files but not with PDF and IMAGES ...
    and your doubt of ..."Is the data the proper length after reading it in?" ..m not getting wat r you asking ...but ... i think regarding data length ..there is no problem... except ... source PDF length is 90.4 kb ..and Target is 90.8 kb..
    thats it...
    So Request u to add some more help ......or should i provide some more details ??

  • SQL Loader or UTL_FILE , Which is better ??

    Hello All,
    In my system I have to Download the data from a file each day in some table.
    The file is of fixed format. And the number of records (lines) in the file is not more than 1000 (say) each day.
    I would like to know for such scenario what will be better to use, SQL Loader or UTL_FILE package to read the file?
    DB - Oracle Database 10g on Linux platform.
    Thanks & Regards,

    Subject: Re: SQL Loader or UTL_FILE , Which is better ??
    Hey,
    My control file 'ATTENDANCE.ctl' is as follows
    load data
    infile 'C:\DATA\06012007.CAP'
    badfile 'C:\DATA\atncap.bad'
    append
    into table NIS.atncap
    COMP_CODE constant 'SP',
    TXN_SRNO sequence(max,1),
    TXN_DATE POSITION(05:12) date 'MM/DD/YYYY' ,
    TXN_ATDATE POSITION(05:16) date 'MM/DD/YYYY HH24:MI',
    TXN_EMPL POSITION(17:24) INTEGER EXTERNAL,
    TXN_TIME POSITION(13:16) ,
    CREATED_BY constant '---',
    CREATED_DT sysdate,
    MODIFIED_BY constant '---',
    MODIFIED_DT sysdate,
    TXN_FILE POSITION(05:12) INTEGER EXTERNAL,
    TXN_INOUT POSITION(26:26) INTEGER EXTERNAL
    and sample data from my file which is to be loaded is
    CC000601200707300025831201FF09D071
    CC000601200708330025836601FF09D17F
    CC000601200710260025830001FF09D271
    CC001201200718480025836201FF09D374
    CC000601200719100025836601FF09D47B
    which contains some flags, date, in/out times, employee code etc. and the positions of all the fields is fixed. The file is generated on daily basis with system date as the file name.
    i.e. above data is from file '06012007.CAP'. We can easily see the date field is at positions 05 to 12 in the file.
    So, for this purpose each time I have to update the control file for 'infile' parameter.
    Thats what I said in my second post.
    Message was edited by:
    Abhijit Deshmukh

  • Loading the data from a packed decimal format file using a sql*loader.

    Hi ,
    In one of the project i'm working here i have to load the data into oracle table from a file using a Sql*loader but the problem is the data file is in the packed decimal format so please let me know if there is any way to do this....I search a lot regarding this ..If anybody faced such type of problem ,then let me the steps to solve this.
    Thanks in advance ,
    Narasingarao.

    declare
    f utl_file.file_type;
    s1 varchar2(200);
    s2 varchar2(200);
    s3 varchar2(200);
    c number := 0;
    begin
    f := utl_file.fopen('TRY','sample1.txt','R');
    utl_file.get_line(f,s1);
    utl_file.get_line(f,s2);
    utl_file.get_line(f,s3);
    insert into sampletable (a,b,c) values (s1,s2,s3);
    c := c + 1;
    utl_file.fclose(f);
    exception
    when NO_DATA_FOUND then
    if utl_file.is_open(f) then utl_file.fclose(f); ens if;
    dbms_output.put_line('No. of rows inserted : ' || c);
    end;SY.

  • 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 Insert Into Performance Difference

    Hello All,
    Im in a situation to measure performance difference between SQL Loader and Insert into. Say there 10000 records in a flat file and I want to load it into a staging table.
    I know that if I use PL/SQL UTL_FILE to do this job performance will degrade(dont ask me why im going for UTL_FILE instead of SQL Loader). But I dont know how much. Can anybody tell me the performance difference in % (like 20% will decrease) in case of 10000 records.
    Thanks,
    Kannan.

    Kannan B wrote:
    Do not confuse the topic, as I told im not going to use External tables. This post is to speak the performance difference between SQL Loader and Simple Insert Statement.I don't think people are confusing the topic.
    External tables are a superior means of reading a file as it doesn't require any command line calls or external control files to be set up. All that is needed is a single external table definition created in a similar way to creating any other table (just with the additional external table information obviously). It also eliminates the need to have a 'staging' table on the database to load the data into as the data can just be queried as needed directly from the file, and if the file changes, so does the data seen through the external table automatically without the need to re-run any SQL*Loader process again.
    Who told you not to use External Tables? Do they know what they are talking about? Can they give a valid reason why external tables are not to be used?
    IMO, if you're considering SQL*Loader, you should be considering External tables as a better alternative.

  • Using a Table Trigger to Trap Error Codes Returned to a SQL Loader seeion

    I would be grateful if anyone knows how to go about this.
    I am trying to insert into a table, details of SQL Loader's rejected records by possibly using a trigger on the loading table to try and trap the error code returned to SQL Loader.
    What I am trying to achieve is to insert in to a table the load or rejected record details that are in SQL Loader’s log file after a load session. For example: records read:, records inserted:, records rejected:...etc..
    My main concern is that the loading table is regularly loaded, with 3m records, has 90 columns, and to check by referencing each column's new value, in the table trigger, may mean very long load times.
    Anyone got any “how to” ideas?
    Many thanks
    Regards
    Carlos

    Folks, thanks for your help.
    Previously, I had briefly considered both ideas and they would work.
    I dismissed the utl_file package solution because I believed that it would take too long to read in each log file line, search for the text and then inserts it into a table.
    I overlooked testing this and when I did (1mb file) it actually was pretty fast. I will go that route.
    Thanks for everyone’s help
    regards
    Carlos

  • 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 and PL/SQL

    A text file contains a single row with 450 comma separated entries.I want to load all the data into an oracle table of 450 columns(separating the comma separated entries e.g A1,2,3 from text file into oracle table as
    col1 col2 col3
    A1 2 3
    but sql loader gives a problem while loading data into more than 250 fields.So how to tackle this problem.
    Please reply soon at [email protected] or [email protected]

    That or you will need to use UTL_FILE in read mode. You will probably want to write a function which parses the commas. There are tons floating around here or on ASKTOM. I am not exactly sure however the max linesize UTL_FILE can read, but it should be a viable option.

  • Sql loader in procedue

    hi,
    i have a a data file and a control file as follows
    data file(data.txt)
    7782, "Clark", "Manager", 7839, 09-June-1981
    7839, "King", "President", , 17-November-1981
    7934, "Miller", "Clerk", 7782, 23-January-1982
    7566, "Jones", "Manager", 7839, 02-April-1981
    control file
    LOAD DATA
    INFILE in_data.txt
    APPEND INTO TABLE scott.emp
    FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY '"'
    (empno, ename, job, mgr, hiredate DATE(20) "DD-Month-YYYY")
    I want to load the above data file into the table emp .I know that we can do it externally by connecting to "SQL LOADER".
    But i would like to know how to do it from within a pl/sql procedure.i.e How can we connect to sql loader from a pl/sql procedure.
    any help pls.
    regards
    RRK

    If you want to use PL/SQL, then either use external tables or UTL_FILE package. No SQL*Loader.
    Cheers
    Sarma.

  • 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;

  • Sql loader control file path........

    Hello all,
    I am running the below query through sql loader from client machine.....
    saved the below query in loader.ctl file, which I kept in "D:\loader.ctl" path....
    options (skip=1)
    load data
    infile 'D:\flat.txt'
    into table GL_INTERFACE
    fields terminated by "," optionally enclosed by '"'
    *( STATUS, LEDGER_ID, USER_JE_SOURCE_NAME, USER_JE_CATEGORY_NAME, ACCOUNTING_DATE, CURRENCY_CODE, DATE_CREATED, CREATED_BY,*
    SEGMENT1, SEGMENT2, SEGMENT3, SEGMENT4, SEGMENT5, ACTUAL_FLAG, ENTERED_DR, ENTERED_CR, GROUP_ID )
    Now my doubt is, to execute the above I have to run the below command in sql loader....
    sqlldr USERID=apps/apps CONTROL=loader.ctl
    In the control file we have given the path for the data file, but * How the command (SQLLDR) identify the path of control file.?*
    Do I need to give or......?
    Is it possible to run the above loader program in client machine? or we have to run only server alone.....
    Please clarify my doubt.
    Thanks and Regards,
    Muthu

    Hi,
    The good practice is, If you are using oracle apps then register a concurrent program of type sql*loader
    put yor ctl file in $<ANY_TOP>/bin. Run Concurrent program to load the data.
    I am just givng you the hints, You search on google u will get multiple ways to do the same things.
    There are lots of ways like using of external table,UTL_FILE or Shell Script to do the same thing.
    Thanks,
    Pritam

  • Using SQL Loader in more than one table

    Hi all,
    I have a new question for those who have used SQL Loader. I
    have never used it and I just know that I need a control file to
    tell SQL Loader what is my flat file layout and what table the
    information goes to. My problem is: my flat file has information
    that goes to two tables in my schema. Those files are very big
    (aprox 280Mb) and I would like to read them just once. Can I do
    this with SQL Loader?
    Other question, is that the fastest way to import data from
    flat files becouse I am using PERL and it takes aprox. 9 hours
    to import 10 of those files. I could use UTL_FILE to read it but
    I heard that SQL Loader was better.
    Thanks for your cooperation
    (Robocop)
    Marcelo Lopes
    Rio de Janeiro - Brazil

    SQL*Loader is the fastest way to load, particularly in direct parallel mode, and can certainly load to multiple tables.
    >
    My advice would be to have a look at the examples given in the Oracle Utilities guide, there is one for loading to multiple
    tables, which I have pasted below.
    >
    -- Loads EMP records from first 23 characters
    -- Creates and loads PROJ records for each PROJNO listed
    -- for each employee
    LOAD DATA
    INFILE &#8217;ulcase5.dat&#8217;
    BADFILE &#8217;ulcase5.bad&#8217;
    DISCARDFILE &#8217;ulcase5.dsc&#8217;
    REPLACE
    INTO TABLE emp
    (empno POSITION(1:4) INTEGER EXTERNAL,
    ename POSITION(6:15) CHAR,
    deptno POSITION(17:18) CHAR,
    mgr POSITION(20:23) INTEGER EXTERNAL)
    INTO TABLE proj
    -- PROJ has two columns, both not null: EMPNO and PROJNO
    WHEN projno != &#8217; &#8217;
    (empno POSITION(1:4) INTEGER EXTERNAL,
    projno POSITION(25:27) INTEGER EXTERNAL) -- 1st proj
    INTO TABLE proj
    WHEN projno != &#8217; &#8217;
    (empno POSITION(1:4) INTEGER EXTERNAL,
    projno POSITION(29:31 INTEGER EXTERNAL) -- 2nd proj
    INTO TABLE proj
    WHEN projno != &#8217; &#8217;
    (empno POSITION(1:4) INTEGER EXTERNAL,
    projno POSITION(33:35) INTEGER EXTERNAL) -- 3rd proj
    see the documentation for a complete explanation of the configuration.
    Thanks, I will read it.

  • IMPORT TEXT W/SQL LOADER

    I have a text file that has multiple records on a line, i want to bring in each as a separate record, then drop to the next line and continue a new set of data. each record is separated by a space. each line has max number of 40 records 54 characters long. I couldn't figure out how to use continueif with sql loader and make this work. Any suggestions??
    Thank you,
    STeven

    Hi Steven
    from whati understand you have a line in a flat file and this line will be seperated to seperate rows and inserted into the db??
    if yes then this might help you
    i suggest you create a function with an IN OUT parameter, which you feed the line and seperate it by a defined seperater, and use each portion as a seperate record/row.
    ie:
    FUNCTION TO_TEXTVAL
    (P_TEXT_LINE IN OUT VARCHAR2)
    RETURN VARCHAR2 IS
    V_SEP NUMBER(1000):= 0;
    V_TEXT_LINE VARCHAR2(10000);
    BEGIN
         V_SEP := INSTR(P_TEXT_LINE,';');
         IF V_SEP = 0 THEN
              V_TEXT_LINE := P_TEXT_LINE;
         ELSE
              V_TEXT_LINE     := SUBSTR(P_TEXT_LINE, 1, V_SEP - 1);
    P_TEXT_LINE     := SUBSTR(P_TEXT_LINE, V_SEP + 1);
         END IF;
         RETURN (V_TEXT_LINE);
    END TO_TEXTVAL;
    here i have used a ';' as my seperator u can replace that with a ' ' (space) to do the job .
    FUNCTION TO_TEXTVAL
    (P_TEXT_LINE IN OUT VARCHAR2)
    RETURN VARCHAR2 IS
    V_SEP NUMBER(1000):= 0;
    V_TEXT_LINE VARCHAR2(10000);
    BEGIN
         V_SEP := INSTR(P_TEXT_LINE,' ');
         IF V_SEP = 0 THEN
              V_TEXT_LINE := P_TEXT_LINE;
         ELSE
              V_TEXT_LINE     := SUBSTR(P_TEXT_LINE, 1, V_SEP - 1);
    P_TEXT_LINE     := SUBSTR(P_TEXT_LINE, V_SEP + 1);
         END IF;
         RETURN (V_TEXT_LINE);
    END TO_TEXTVAL;
    then you can use this function in a procedure that calls UTL_FILE.GET_LINE builtin
    ie:
         UTL_FILE.GET_LINE(v_filehandle, v_text);
                   v_item_code := TO_TEXTVAL(v_text);
                   v_item_qty := TO_TEXTVAL(v_text);
                   v_prod_date := TO_DATE(TO_TEXTVAL(v_text), 'MM/DD/YYYY HH:MI:SS AM');
    hope this helps.
    Regards
    Tony G.

Maybe you are looking for

  • MacBook Air heats up quickly, is slow, freezes

    Hi there. My MBA has recently started acting up -- CPU gets pegged and fan spins up to max with seemingly no load. Freezes on occasion -- just basically sluggish and sickly performance. Report follows. Any advice would be very much appreciated: Probl

  • How to disappear the combobox

    I try the following code and i got some trouble. if I select the value in combobox (different value), the combobox will disappear. But when I select the default value, the combobox will not disappear. So, how can I disappear the combobox when user se

  • Event structure input event question

    I'm using a state machine to do some data decoding stuff. The default initial state is Idle, which checks an output boolean value from a FIFO buffer. If the boolean value is True, go to the next state; otherwise, keeps waiting. See attached "idle_noE

  • Why does my digital AV adapter not work with my iPad

    Why does my digital AV adapter not work with my iPad

  • How do I get the IPad2 to find printer?

    How do I get the IPad2 to find printer? I've set the printer up with the Bonjour service.