Dbms_lob.LOADFROMFILE()

What are the types, parameters and syntax of this LOADFROMFILE function ??
Tx in advance,
Xavier

This actually a procedure. The information you seek can be found in the "PL/SQL Supplied Packages Reference" guide.
http://otn.oracle.com/docs/products/oracle8i/doc_library/817_doc/appdev.817/a76936/dbms_lo2.htm#1009007

Similar Messages

  • Dbms_lob.loadfromfile help

    sorry in advance if this is basic - SQL developer virgin here . . .
    Using the examples in this document
    http://download-west.oracle.com/docs/cd/B14117_01/appdev.101/b10840/mm_uses.htm
    specifically the code:
    INSERT INTO soundtable(id, sound) VALUES (1, EMPTY_BLOB());
    COMMIT;
    DECLARE
    f_lob BFILE := BFILENAME('AUDDIR','chimes.wav');
    b_lob BLOB;
    Lob BLOB;
    Length INTEGER;
    BEGIN
    SELECT sound INTO b_lob FROM soundtable WHERE id=1 FOR UPDATE;
    -- Open the LOBs.
    dbms_lob.open(f_lob, dbms_lob.file_readonly);
    dbms_lob.open(b_lob, dbms_lob.lob_readwrite);
    dbms_lob.loadfromfile
    (b_lob, f_lob, dbms_lob.getlength(f_lob));
    -- Close the LOBs.
    dbms_lob.close(b_lob);
    dbms_lob.close(f_lob);
    COMMIT;
    -- Select the LOB:
    SELECT sound INTO Lob FROM soundtable
    WHERE ID = 1;
    -- Opening the LOB is optional.
    DBMS_LOB.OPEN (Lob, DBMS_LOB.LOB_READONLY);
    -- Get the length of the LOB.
    length := DBMS_LOB.GETLENGTH(Lob);
    IF length IS NULL THEN
    DBMS_OUTPUT.PUT_LINE('LOB is null.');
    ELSE
    DBMS_OUTPUT.PUT_LINE('The length is '|| length);
    END IF;
    -- Closing the LOB is mandatory if you have opened it.
    DBMS_LOB.CLOSE (Lob);
    END;
    2 questions for anyone who has done this before or has an opinion:
    1) In the initial insert -- INSERT INTO soundtable(id, sound) VALUES (1, EMPTY_BLOB()); -- if the value for the column "id" is sequence.next_val I could end up with an "id" of 3012 for example:
    so how would I find out what value the "id" is before doing the next step:
    SELECT sound INTO b_lob FROM soundtable WHERE id=1 FOR UPDATE;
    I would have to do:
    SELECT sound INTO b_lob FROM soundtable WHERE id=<whatever_was_generated_by_the_sequence> FOR UPDATE;
    and if there are 10 people inserting at about the same time, how the heck am I supposed to know which "id" goes with which content file?
    any help is appreciated

    You can use the returning clause to store the generated sequence value that was inserted into id into a variable, then reference that variable in the rest of your code, as demonstrated below.
    SCOTT@10gXE> CREATE TABLE soundtable
      2    (id    NUMBER,
      3       sound BLOB DEFAULT EMPTY_BLOB ())
      4  /
    Table created.
    SCOTT@10gXE> CREATE SEQUENCE your_sequence
      2  /
    Sequence created.
    SCOTT@10gXE> VARIABLE g_id_seq NUMBER
    SCOTT@10gXE> INSERT INTO soundtable (id)
      2  VALUES (your_sequence.NEXTVAL)
      3  RETURNING id INTO :g_id_seq
      4  /
    1 row created.
    SCOTT@10gXE> COMMIT
      2  /
    Commit complete.
    SCOTT@10gXE> CREATE OR REPLACE DIRECTORY auddir AS 'C:\WINDOWS\Media'
      2  /
    Directory created.
    SCOTT@10gXE> SET SERVEROUTPUT ON
    SCOTT@10gXE> DECLARE
      2    f_lob  BFILE := BFILENAME ('AUDDIR', 'chimes.wav');
      3    b_lob  BLOB;
      4    Lob    BLOB;
      5    Length INTEGER;
      6  BEGIN
      7 
      8    SELECT sound
      9    INTO   b_lob
    10    FROM   soundtable
    11    WHERE  id = :g_id_seq
    12    FOR UPDATE;
    13 
    14    dbms_lob.open (f_lob, dbms_lob.file_readonly);
    15    dbms_lob.open (b_lob, dbms_lob.lob_readwrite);
    16    dbms_lob.loadfromfile
    17        (b_lob, f_lob, dbms_lob.getlength (f_lob));
    18    dbms_lob.close(b_lob);
    19    dbms_lob.close(f_lob);
    20    COMMIT;
    21 
    22    SELECT sound
    23    INTO   Lob
    24    FROM   soundtable
    25    WHERE  ID = :g_id_seq;
    26    length := DBMS_LOB.GETLENGTH (Lob);
    27    IF length IS NULL THEN
    28        DBMS_OUTPUT.PUT_LINE ('LOB is null.');
    29    ELSE
    30        DBMS_OUTPUT.PUT_LINE ('The length is '|| length);
    31    END IF;
    32  END;
    33  /
    The length is 55776
    PL/SQL procedure successfully completed.
    SCOTT@10gXE>

  • DBMS_LOB.LOADFROMFILE causes numeric value error

    The code below causes a numeric value error when I do LOADFROMFILE. Do you have any suggestions. Thanks.
    declare
    locator bfile;
    cloblocator clob;
    buffer varchar2(1000);
    lsize integer := 0;
    amount INTEGER := 1000;
    v_filename varchar(50) := 'notify_offer_tbl';
    begin
    locator := bfilename('IDEA_DATA_DIR','notify_offer_tbl');
    insert into imsa.t_unix_logs values ('notify_offer_tbl', locator, empty_clob());
    Select fileloclob into cloblocator from imsa.t_unix_logs where filename ='notify_offer_tbl' for update;
    if dbms_lob.fileexists(locator) = 1 then
    dbms_output.put_line('Exists');
    if dbms_lob.fileisopen(locator) = 1 then
    dbms_output.put_line('open');
    else
    dbms_output.put_line('close');
    dbms_lob.fileopen(locator, DBMS_LOB.FILE_READONLY);
    lsize := dbms_lob.getlength(locator);
    dbms_output.put_line('File Length: ' || to_char(lsize));
    DBMS_LOB.LOADFROMFILE(cloblocator, locator, lsize);
    commit;
    end if;
    end if;
    DBMS_LOB.READ(cloblocator, amount, 1, buffer);
    dbms_output.put_line('File ' || buffer);
    DBMS_LOB.FILECLOSE(locator);
    EXCEPTION
    WHEN OTHERS THEN
    dbms_output.put_line('Error -- ' || SUBSTR(sqlerrm, 1, 200));
    DBMS_LOB.FILECLOSE(locator);

    Yes. The column clobcol (in the SELECT in your example) should be set to empty_clob() or already contain a CLOB, before selecting the column value into the local variable. The example in the DBMS_LOB documentation page is misleading as it does not mention this.
    Note also that it is best to use dbms_lob.getlength to establish the value for
    the amount parameter.
    Hope this helps others searching for information on this - I have spent some painful hours working this out!
    Peter

  • DBMS_LOB.loadfromfile don't work?

    I have a word doc file, I write a stored proc using DBMS_LOB.loadfromfile to load it into a BLOB record.
    -the DBMS_LOB.getlength successfully got the length
    -but when I use form ole container to show it....the ole container show nothing.
    -if I use initialize_container ... it works....why?
    my stored proc :-
    PROCEDURE XXinsert_file AS
    lobd BLOB;
    fils BFILE := BFILENAME('UPLOAD', 'A1.TXT');
    length integer;
    BEGIN
    -- update ole_container set ole_content = empty_blob() where container_id = 'CH050100001';
    SELECT ole_content INTO lobd FROM ole_container
    WHERE container_id = 'CH050100001' for update;
    dbms_lob.fileopen(fils, dbms_lob.file_readonly);
    length := dbms_lob.getlength(fils);
    dbms_lob.loadfromfile(lobd, fils, length);
    update ole_container set file_length = length where container_id = 'CH050100001';
    dbms_lob.fileclose(fils);
    COMMIT;
    END XXinsert_file;

    Forms wraps files in a larger structure before storing them as blobs. So in Forms you can only read files that were loaded through Forms, and using dbms_lob you can only read files that were loaded through dbms_lob.

  • Use dbms_lob.loadfromfile to handle chinese character

    Hello,
    I have a database with NLS_LANG=TRADITIONAL CHINESE_HONG KONG.ZHT16BIG5
    There is a table with clob type column.
    I've tried to use dbms_lob.loadfromfile to load file content into the clob type column.
    But the result is that no matter the file is english or chinese character, the column's content will become "monster".
    Is there any method to solve this problem ?
    Can anyone help ?
    Rgds,
    Edward
    null

    Hi, it's me again.
    I just want to share my experience and hope that it can help someone and someone can help me !
    I've created a database with UTF8 as my character set.
    With session's character set = UTF8, when I tried to use dbms_lob.loadfromfile to load data into clob column from a file with chinese character content. What has been stored is "monster" character. I know that it's because bfile is with binary type and will not do character set conversion when loadfromfile is being used.
    I've tried the other way, I use dbms_lob.read to read the file and use utl_raw to convert it to UTF8 character set and store it in a varchar2. It works !
    But what I want is to store the chinese character into the clob column.
    I've tried to use the following option but still fail :
    - convert (it's seems that has no effect)
    - utl_raw.translate (it always get oracle error, I've use this as : utl_raw.translate(RAW, 'UTF8', 'UTF8'))
    - utl_raw.convert
    Hope that some have experience can help me !
    Rgds,
    Edward
    null

  • DBMS_LOB.LOADFROMFILE ignores new lines

    Hi All,
    I am using UTL_FILE.put_line for creating a text file. However when i try to load it into a blob, all new lines are ignored and text is displayed in one line.
    Any idea about this?
    DB: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production

    Bill,
    this is an Oracle Forms forum and your question is database related. I suggest to try the database forum here on OTN.
    Frank

  • Error in using DBMS_LOB Package

    Hi,
    I am attaching a PDF File through a database procedure as shown below
    create or replace procedure load_document(document_id in number, filename IN varchar2, doc_desc IN VARCHAR2, doc_type IN VARCHAR2) as
    f_lob bfile;
    b_lob blob;
    --document_name varchar2(30);
    --mime_type varchar2(30);
    document_name oea_documents.document_name%TYPE;
    mime_type oea_documents.document_mime_type%TYPE;
    dot_pos number;
    v_file_type VARCHAR2(10);
    begin
    -- Find the position of the dot ('.') located in the filename
    dot_pos := instr(filename,'.');
    -- Get the filename without extension and use it as image name
    document_name := substr(filename,1,dot_pos-1);
    -- Build the mime type . Retrieve the file extension and add it to 'image/'
    v_file_type := SUBSTR( filename, dot_pos+1, Length(Filename) );
    IF ( UPPER(v_file_type) IN ('JPG','JPEG','TIF','TIFF','GIF') ) THEN
    mime_type := 'image/'||substr( filename , dot_pos+1 , length(filename) );
    ELSIF ( UPPER(v_file_type) = 'PDF' ) THEN
    mime_type := 'application/pdf';
    ELSIF ( UPPER(v_file_type) = 'DOC' )THEN
    mime_type := 'application/msword';
    ELSIF ( UPPER( v_file_type) = 'XLS') THEN
    mime_type := 'application/ms-excel';
    ELSE
    mime_type := 'image/'||substr( filename , dot_pos+1 , length(filename) );
    END IF;
    insert into oea_documents (document_id,
    document_name,
    document_mime_type,
    document,
    document_description,
    document_type
    values(document_id, document_name, mime_type, empty_blob(),doc_desc,doc_type) return document into b_lob;
    -- /!\ Directory name has to be UpperCase !
    f_lob := bfilename('FILE_LOAD',filename);
    o_dset_test('5');
    dbms_lob.fileopen(f_lob,dbms_lob.file_readonly);
    o_dset_test('6');
    dbms_lob.loadfromfile(b_lob,f_lob,dbms_lob.getlength(f_lob) );
    dbms_lob.fileclose(f_lob);
    commit;
    end;
    FILE_LOAD is a folder on the database server(unix).
    I have also tried to give the full path on the unix databse server instead of FILE_LOAD directory but then it gives error ora-22285.
    while executing this procedure I am getting the error ora-22288(Invalid file or directory).
    But this occurs randomly
    For instance i tried to attach a pdf file with the name cross.pdf ,it gave me the above error and when i renamed the file as Cross.pdf it attached successfully.
    The error comes whilke executing the statement dbms_lob.fileopen(f_lob,dbms_lob.file_readonly);
    Please guide on the above issue.

    Hi,
    Welcome to the forum!
    user1356624 wrote:
    f_lob := bfilename('FILE_LOAD',filename);
    FILE_LOAD is a folder on the database server(unix).
    I have also tried to give the full path on the unix databse server instead of FILE_LOAD directory but then it gives error ora-22285.The first argument to BFILENAME is the name of a directory object, as found in the directory_name column of all_directories. That is not the same thing as a folder name, which is found in the directory_path column of all_directories. Look up [CREATE DIRECTORY|http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/statements_5007.htm#sthref6211] in the SQL Language manual for a description of Oracle's directory objects.
    If you have problems with this, post the results of
    SELECT  *
    FROM    all_directories;It might also be useful to see the Oracle "CREATE DIRECTORY" command that was used.
    As you probably noticed, this site compresses white space by default.
    When you post code or results on this site, type these 6 characters:
    (small letters only, inside curly brackets) before and after sections of formatted text, to preserve spacing.
    Edited by: Frank Kulash on Aug 10, 2009 3:35 PM
    Added link.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Need help in using dbms_lob.read

    I need to upload a file into an Oracle table into a Blob column. The file name along with the file contents are all in one BLOB column.
    Once that is done I need to read from the file and extract the file contents and load it into a staging table.
    File being uploaded is a *.CSV* file.
    E.g. Of the .CSV file is: ABC.csv file and its contents will look like:
    1,Hello,Nisha
    2,Hi,Ravi
    3,Bye, Rahul
    Etc…..
    Therefore the table containing the BLOB column will contain:
    File Creation_date
    ABC.csv 09/11/2009
    How can I read a file from the BLOB column and upload into a staging table?
    Final Staging table should look like:
    Record Number Greet Name
    1 Hello Nisha
    2 Hi Ravi
    3 Bye Rahul
    I think I am suppose to use dbms_lob.read, but I am not really sure how to use it. If there is any script, kindly mail me the same.
    Thanks....

    Nisha,
    Check this example (test) and see if it can be any help. I have utl_file and sqlldr
    First Method -- I loaded alert.log successfully and you can imagine how big this file can be (5MB in my test case)
    create table t1clob
    ( clob_text clob);
    CREATE OR REPLACE DIRECTORY DIR AS '/path_to_csv_file/;
    DECLARE
       clob_data   CLOB;
       clob_file   BFILE;
    BEGIN
       INSERT INTO t1clob
       VALUES (EMPTY_CLOB ())
       RETURNING clob_text INTO clob_data;
       clob_file   := BFILENAME ('DIR', ABC.csv');
       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
    Example of controlfile
    LOAD DATA
    INFILE alert.log "STR '|\n'"
    REPLACE INTO  table t1clob
       clob_text char(30000000)
    )Hope this helps.

  • How to insert 10 files from a directory to database,can i use dbms_lob??

    Hii
    I want to load 10files in my local drive into a table...how to do this.I'm able to do this individually using dbms_lob.loadfromfile and bfil but ,I want to copy all the files i that drive at time to my table...Is there any way to do this..?

    Okay... Here is some sample code that will help you store the files in binary format into db tables.
    create table t_blob(bid integer, blbdata blob);
    select * from t_blob;
    create or replace directory ext_tab_dir as 'C:\Oracle\ExtTab_Dir';
    grant read, write on directory ext_tab_dir to priya;
    declare
          src_file bfile;
          dest_file blob;
          len_file pls_integer;
    begin
          src_file:=bfilename('EXT_TAB_DIR','XML.doc');
          insert into t_blob values(1,empty_blob()) returning blbdata into dest_file;
          select blbdata into dest_file
            from t_blob
           where bid=1 for update;
          dbms_lob.fileopen(src_file,dbms_lob.file_readonly);
          len_file:=dbms_lob.getlength(src_file);
          dbms_output.put_line(len_file);
          dbms_lob.loadfromfile(dest_file,src_file,len_file);
          update t_blob
             set blbdata = dest_file
           where bid = 1;
          dbms_lob.fileclose(src_file);
    end;
    /I haven't used the wrap utility yet, so not much hands on with it. I guess the wrap utility at the OS level. Not sure if it will work at SQL prompt.

  • Using dbms_lob to load image into table

    I am trying to load a set of images from my DB drive into a table. This works fine when I try to load only 1 record. If I try to load more than 1 record, first gets created but I get this error, and it doesn't load the images for the rest of them.
    ORA-22297:     warning: Open LOBs exist at transaction commit time
    Cause:     An attempt was made to commit a transaction with open LOBs at transaction commit time.
    Action:     This is just a warning. The transaction was commited successfully, but any domain or functional indexes on the open LOBs were not updated. You may want to rebuild those indexes.
    Am I missing something in the code that's needed?
    in_file UTL_FILE.FILE_TYPE;
    bf bfile;
    b blob;
    src_offset integer := 1;
    dest_offset integer := 1;
    CURSOR get_pics is select id from emp;
    BEGIN
    FOR x in get_pics LOOP
    BEGIN
    insert into stu_pic(id,student_picture)
    values(x.id,empty_blob()) returning student_picture into b;
    l_picture_uploaded := 'Y';
    bf := bfilename('INTERFACES',x.student_id || '.' || p_image_type);
    dbms_lob.fileopen(bf,dbms_lob.file_readonly);
    dbms_lob.open(b,dbms_lob.lob_readwrite);
    dbms_lob.loadBlobFromFile(b,bf,dbms_lob.lobmaxsize,dest_offset,src_offset);
    dbms_lob.close(b);
    dbms_lob.fileclose(bf);
    EXCEPTION when dup_val_on_index then null;
    END;
    END LOOP;
    END;

    There are two methods you can use.
    1. Create an external table with those images(BLOB column) and then use that external table to insert into another table.
    Demo as follows:
    This is my pdf files
    C:\Saubhik\Assembly\Books\Algorithm>dir *.pdf
    Volume in drive C has no label.
    Volume Serial Number is 6806-ABBD
    Directory of C:\Saubhik\Assembly\Books\Algorithm
    08/16/2009  02:11 PM         1,208,247 algorithms.pdf
    08/17/2009  01:05 PM        13,119,033 fci4all.com.Introduction_to_the
    d_Analysis_of_Algorithms.pdf
    09/04/2009  06:58 PM        30,375,002 sedgewick-algorithms.pdf
                   3 File(s)     44,702,282 bytes
                   0 Dir(s)   7,474,593,792 bytes free
    C:\Saubhik\Assembly\Books\Algorithm>This is my file with which I'll load the pdf files as BLOB
    C:\Saubhik\Assembly\Books\Algorithm>type mypdfs.txt
    Algorithms.pdf,algorithms.pdf
    Sedgewick-Algorithms.pdf,sedgewick-algorithms.pdf
    C:\Saubhik\Assembly\Books\Algorithm>Now the actual code
    SQL> /* This is my directory object */
    SQL> CREATE or REPLACE DIRECTORY saubhik AS 'C:\Saubhik\Assembly\Books\Algorithm';
    Directory created.
    SQL> /* Now my external table */
    SQL> /* This table contains two columns. 1.pdfname contains the name of the file
    DOC>   and 2.pdfFile is a BLOB column contains the actual pdf*/ 
    SQL> CREATE TABLE mypdf_external (pdfname VARCHAR2(50),pdfFile BLOB)
      2         ORGANIZATION EXTERNAL (
      3           TYPE ORACLE_LOADER
      4            DEFAULT DIRECTORY saubhik
      5            ACCESS PARAMETERS (
      6              RECORDS DELIMITED BY NEWLINE
      7              BADFILE saubhik:'lob_tab_%a_%p.bad'
      8              LOGFILE saubhik:'lob_tab_%a_%p.log'
      9              FIELDS TERMINATED BY ','
    10              MISSING FIELD VALUES ARE NULL
    11               (pdfname char(100),blob_file_name CHAR(100))
    12              COLUMN TRANSFORMS (pdfFile FROM lobfile(blob_file_name) FROM (saubhik) BLOB)
    13            )
    14            LOCATION('mypdfs.txt')
    15         )
    16         REJECT LIMIT UNLIMITED;
    Table created.
    SQL> SELECT pdfname,DBMS_LOB.getlength(pdfFile) pdfFileLength
      2  FROM   mypdf_external;
    PDFNAME                                            PDFFILELENGTH
    Algorithms.pdf                                           1208247
    Sedgewick-Algorithms.pdf                                30375002
    SQL> Now, you can use this table for any operation very easily. Even for your loading into another table!.
    2. Use of DBMS_LOB like this
    /* Loading a image Winter.jpg in the BLOB column as BLOB!*/
    DECLARE
      v_src_blob_locator BFILE := BFILENAME('SAUBHIK', 'Winter.jpg');
      v_amount_to_load   INTEGER := 4000;
      dest_lob_loc BLOB;
    BEGIN
      --Insert a empty row with id 1
      INSERT INTO test_my_blob_clob VALUES(1,EMPTY_BLOB(),EMPTY_CLOB())
       RETURNING BLOB_COL INTO dest_lob_loc;
      DBMS_LOB.open(v_src_blob_locator, DBMS_LOB.lob_readonly);
      v_amount_to_load := DBMS_LOB.getlength(v_src_blob_locator);
      DBMS_LOB.loadfromfile(dest_lob_loc, v_src_blob_locator, v_amount_to_load);
      DBMS_LOB.close(v_src_blob_locator);
      COMMIT;
    --id=1 is created with Winter.jpg populated in BLOB_COL and CLOB_COL is empty.  
    END;Now user this code to create a procedure with parameter and use that in loop.

  • DBMS_LOB.FILEOPEN(dir, fname) gives non-existent dir or file error

    Hello!
    I've been trying to load an image file into the oracle database using the DBMS_LOB loadfromfile procedure. In order to do this, I first have to open the appropriate file which I do using
    temp_bfile := bfilename('temp_dir', in_filename);
    where in_filename is a string having the appropriate filename. and 'temp_dir' is a directory object created as follows:
    CREATE DIRECTORY temp_dir AS 'F:\';
    Next when I do a
    DBMS_LOB.FILEOPEN(temp_bfile, LOB_READONLY);
    I get an exception ORA-22285:non-existent directory or file.
    What am I doing wrong? Is the way I've created the directory object correct. I work on an NT machine.
    Mona

    Not sure if the UTL_FILE package is the same but if you don't set the "utl_file_dir" variable in the INIT.ORA file prior to calling the FOPEN procedure you will get a similiar error. There may be an equivalent parameter for the DBMS_LOB package.
    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Mona Marathe ([email protected]):
    Hello!
    I've been trying to load an image file into the oracle database using the DBMS_LOB loadfromfile procedure. In order to do this, I first have to open the appropriate file which I do using
    temp_bfile := bfilename('temp_dir', in_filename);
    where in_filename is a string having the appropriate filename. and 'temp_dir' is a directory object created as follows:
    CREATE DIRECTORY temp_dir AS 'F:\';
    Next when I do a
    DBMS_LOB.FILEOPEN(temp_bfile, LOB_READONLY);
    I get an exception ORA-22285:non-existent directory or file.
    What am I doing wrong? Is the way I've created the directory object correct. I work on an NT machine.
    Mona<HR></BLOCKQUOTE>
    null

  • Loading Clob and Blob data using DBMS_LOB

    I am loading some data into a table that has five columns, two of which are defined as BLOB and CLOB respectively. I get the following errors after the pl/sql procedure that loads it has completed running :
    ERROR:ORA-21560: argument 3 is null,
    invalid, or out of range
    ERROR:ORA-22297: warning: Open LOBs exist
    at transaction commit time.
    The following is the outline of the code that loads the table:
    CREATE OR REPLACE PROCEDURE load_data(dir,seq_val,file_name,
    details, etc <== all these are passed in) IS
    dest_loc BLOB;
    src_loc BFILE;
    Amount INTEGER;
    new_dir string(1000);
    new_file string(1000);
    BEGIN
    new_dir := ''||dir||'';
    new_file := ''||file_name||'';
    src_loc := BFileName(new_dir,new_file);
    Amount := dbms_lob.getlength(src_loc);
    insert into table A
    (id
    ,ver
    ,ver
    ,fil_nm <== This field is a BLOB
    ,details <== This Field is a CLOB
    values
    (seq_val
    ,1
    ,version
    ,empty_blob()
    ,detailed_infor
    --dbms_output.put_line(Amount);
    SELECT fil_nm INTO dest_loc FROM table A WHERE id = seq_val FOR UPDATE;
    /* Opening the LOB is mandatory: */
    --dbms_output.put_line('IN SELECT...');
    DBMS_LOB.OPEN(src_loc, DBMS_LOB.LOB_READONLY);
    /* Opening the LOB is optional: */
    DBMS_LOB.OPEN(dest_loc, DBMS_LOB.LOB_READWRITE);
    DBMS_LOB.LOADFROMFILE(dest_loc, src_loc, Amount);
    /* Closing the LOB is mandatory if you have opened it: */
    DBMS_LOB.CLOSE(dest_loc);
    DBMS_LOB.CLOSE(src_loc);
    --dbms_output.put_line('After SELECT...');
    COMMIT;
    END
    Any feedback would be really appreciated. Thanks.

    I assume thats when the ORA-21560: argument 3 is null, invalid, or out of range error occurs. I'm also wondering why and what the other error means saying LOBs are open during transaction commit time. The data is coming from an xml file that is in the following format.
    - <NAME>
    <FIL_NM>TEST.PDF</FIL_NM>
    <VER>2</VER>
    <DETAILS>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    xxxxxxxxxxxxxyyyyyyyyyyyyyyyyyyzzzzzzzzzmmmmmmsusssuitttttretc</DETAILS>
    </REPORT>
    <NAME/>
    So what this procedure is doing is opening the pdf and loading the data into the BLOB. I just can't understand what is causing those errors.

  • DBMS_LOB.WRITEAPPEND - HELP!

    Why is my code failing? All I am doing is reading text from an external file (UTL_FILE package) and appending it onto an NCLOB variable, but the WRITEAPPEND to the NCLOB variable is failiing. I know the WRITEAPPEND is failinb because I instrumented the code with DBMS_OUTPUT statement. I get the following error message with the following code:
    DECLARE
    ERROR at line 1:
    ORA-22275: invalid LOB locator specified
    ORA-06512: at "SYS.DBMS_LOB", line 328
    ORA-06512: at line 39
    ORA-22275: invalid LOB locator specified
    CODE
    ====
    DECLARE
    the_val NCLOB;
    filehdl UTL_FILE.FILE_TYPE;
    buf VARCHAR2(32765);
    still_reading BOOLEAN := TRUE;
    BEGIN
    filehdl := UTL_FILE.FOPEN('/tmp','reqmnt.txt','r',32765);
    DBMS_LOB.CREATETEMPORARY(the_val, TRUE);
    DBMS_LOB.OPEN(the_val, DBMS_LOB.LOB_READWRITE);
    SELECT empty_clob() INTO the_val
    FROM DUAL;
    WHILE ( still_reading ) LOOP
    BEGIN
    UTL_FILE.GET_LINE(filehdl, buf);
    -- Append the line to the variable.
    -- THE FOLLOWING WRITEAPPEND STATEMENT IS FAILING AT RUNTIME
    DBMS_LOB.WRITEAPPEND(the_val, 32765, TRANSLATE( buf USING NCHAR_CS ));
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    still_reading := FALSE;
    UTL_FILE.FCLOSE(filehdl);
    WHEN OTHERS THEN
    UTL_FILE.FCLOSE(filehdl);
    RAISE;
    END;
    END LOOP;
    DBMS_LOB.CLOSE(the_val);
    DBMS_LOB.FREETEMPORARY(the_val);
    -- <NOW DO SOME SORT OF INSERT STATEMENT WITH the_val>
    EXCEPTION
    WHEN OTHERS THEN
    DBMS_LOB.CLOSE(the_val);
    DBMS_LOB.FREETEMPORARY(the_val);
    RAISE;
    END;
    null

    You can use the returning clause to store the generated sequence value that was inserted into id into a variable, then reference that variable in the rest of your code, as demonstrated below.
    SCOTT@10gXE> CREATE TABLE soundtable
      2    (id    NUMBER,
      3       sound BLOB DEFAULT EMPTY_BLOB ())
      4  /
    Table created.
    SCOTT@10gXE> CREATE SEQUENCE your_sequence
      2  /
    Sequence created.
    SCOTT@10gXE> VARIABLE g_id_seq NUMBER
    SCOTT@10gXE> INSERT INTO soundtable (id)
      2  VALUES (your_sequence.NEXTVAL)
      3  RETURNING id INTO :g_id_seq
      4  /
    1 row created.
    SCOTT@10gXE> COMMIT
      2  /
    Commit complete.
    SCOTT@10gXE> CREATE OR REPLACE DIRECTORY auddir AS 'C:\WINDOWS\Media'
      2  /
    Directory created.
    SCOTT@10gXE> SET SERVEROUTPUT ON
    SCOTT@10gXE> DECLARE
      2    f_lob  BFILE := BFILENAME ('AUDDIR', 'chimes.wav');
      3    b_lob  BLOB;
      4    Lob    BLOB;
      5    Length INTEGER;
      6  BEGIN
      7 
      8    SELECT sound
      9    INTO   b_lob
    10    FROM   soundtable
    11    WHERE  id = :g_id_seq
    12    FOR UPDATE;
    13 
    14    dbms_lob.open (f_lob, dbms_lob.file_readonly);
    15    dbms_lob.open (b_lob, dbms_lob.lob_readwrite);
    16    dbms_lob.loadfromfile
    17        (b_lob, f_lob, dbms_lob.getlength (f_lob));
    18    dbms_lob.close(b_lob);
    19    dbms_lob.close(f_lob);
    20    COMMIT;
    21 
    22    SELECT sound
    23    INTO   Lob
    24    FROM   soundtable
    25    WHERE  ID = :g_id_seq;
    26    length := DBMS_LOB.GETLENGTH (Lob);
    27    IF length IS NULL THEN
    28        DBMS_OUTPUT.PUT_LINE ('LOB is null.');
    29    ELSE
    30        DBMS_OUTPUT.PUT_LINE ('The length is '|| length);
    31    END IF;
    32  END;
    33  /
    The length is 55776
    PL/SQL procedure successfully completed.
    SCOTT@10gXE>

  • DBMS_LOB을 이용한 BLOB 데이타 HANDLING 예제 프로그램

    제품 : PRECOMPILERS
    작성날짜 : 1998-09-15
    DBMS_LOB을 이용한 BLOB 데이타 HANDLING 예제 프로그램
    ==================================================
    1) select 하는 예제
    - pro*c 2.2에서 compile하는 경우는 package로 DBMS_LOB package 호출을
    encapsulate 해서 사용해야 하고, proc 8.0 이상에서 compile하는 경우
    DBMS_LOB package를 직접 호출하는 것이 가능하다.
    - make 방법
    PRO*C 8.0인 경우
    $ make -f demo_proc.mk EXE=my_prog OBJS=my_prog.o build \
    PROCFLAGS="sqlcheck=full userid=scott/tiger define=V8"
    PRO*C 2.2:
    $ setenv TWO_TASK v8_alias
    $ make -f proc.mk EXE=my_prog OBJS=my_prog.o build \
    PROCFLAGS="sqlcheck=full userid=scott/tiger"
    - 수행 SQL Script
    create or replace package blob_it as
    my_blob blob;
    function get_blob_len return number;
    procedure read_blob(amount in out number, offset in number,
    buf in out raw);
    end;
    create or replace package body blob_it as
    function get_blob_len return number is
    begin
    return DBMS_LOB.GETLENGTH(my_blob);
    end;
    procedure read_blob(amount in out number, offset in number,
    buf in out raw) is
    begin
    DBMS_LOB.READ(my_blob,amount,offset,buf);
    end;
    end;
    drop table lob_tab;
    create table lob_tab (c1 number, c2 blob);
    insert into lob_tab values (1,
    utl_raw.cast_to_raw('AAAAAAAaaaaaaaaaa'));
    - Program 예제
    #include <stdio.h>
    #include <string.h>
    #define TERM(X) ( X.arr[X.len] = '\0' )
    #define SLEN(X) ( X.len = strlen((char *)X.arr) )
    #define READ_SIZE 60
    EXEC SQL INCLUDE SQLCA;
    /* Structure for VARRAW */
    typedef struct {short len; char arr[READ_SIZE];} vr;
    EXEC SQL BEGIN DECLARE SECTION;
    VARCHAR oracleid[20];
    EXEC SQL TYPE vr IS VARRAW(READ_SIZE);
    vr my_vr;
    EXEC SQL END DECLARE SECTION;
    FILE *fp;
    main()
    char action_str[30];
    long amount;
    long offset;
    short done;
    long total;
    EXEC SQL WHENEVER SQLERROR DO o_error(action_str);
    strcpy( (char *)oracleid.arr, "scott/tiger" );
    SLEN( oracleid );
    strcpy( action_str, "connecting to d/b" );
    EXEC SQL CONNECT :oracleid;
    fp = fopen("my_blob.dat","wb");
    strcpy( action_str, "fetching blob locator" );
    EXEC SQL EXECUTE
    BEGIN
    select c2 into blob_it.my_blob from lob_tab
    where c1 = 1;
    #ifndef V8
    :total := blob_it.get_blob_len;
    #else
    :total := DBMS_LOB.GETLENGTH(blob_it.my_blob);
    #endif
    END;
    END-EXEC;
    amount = READ_SIZE;
    offset = 1;
    done = 0;
    strcpy( action_str, "reading from blob" );
    while (!done)
    EXEC SQL EXECUTE
    BEGIN
    #ifndef V8
    blob_it.read_blob(:amount,:offset,:my_vr);
    #else
    DBMS_LOB.READ(blob_it.my_blob,:amount,:offset,:my_vr);
    #endif
    END;
    END-EXEC;
    offset += amount;
    if (offset >= total)
    done = 1;
    fwrite(my_vr.arr,(size_t)amount,(size_t)1,fp);
    fclose(fp);
    EXEC SQL WHENEVER SQLERROR CONTINUE;
    EXEC SQL ROLLBACK WORK RELEASE;
    int o_error( action_str )
    char *action_str;
    int i;
    char error_str[150];
    EXEC SQL WHENEVER SQLERROR CONTINUE;
    for ( i = 0; i < sqlca.sqlerrm.sqlerrml; i++ )
    error_str[i] = sqlca.sqlerrm.sqlerrmc;
    error_str[i] = '\0';
    printf( "\nFailed with following Oracle error while %s:\n\n%s",
    action_str, error_str );
    EXEC SQL ROLLBACK WORK RELEASE;
    exit(1);
    2) insert 하는 예제
    - 수행 SQL문
    create directory BFILE_DIR as '/mnt3/rctest80/ldt';
    - make 방법
    $ make -f demo_proc.mk EXE=my_prog OBJS=my_prog.o build \
    PROCFLAGS="sqlcheck=full userid=scott/tiger"
    - Bfile을 이용하여 데이타를 로드하는 프로그램 예제
    #include <stdio.h>
    #include <string.h>
    #define SLEN(X) ( X.len = strlen((char *)X.arr) )
    EXEC SQL INCLUDE SQLCA;
    VARCHAR oracleid[20];
    FILE *fp;
    main()
    char action_str[30];
    EXEC SQL WHENEVER SQLERROR DO o_error(action_str);
    strcpy( (char *)oracleid.arr, "scott/tiger" );
    SLEN( oracleid );
    strcpy( action_str, "connecting to d/b" );
    EXEC SQL CONNECT :oracleid;
    EXEC SQL EXECUTE
    DECLARE
    lobd BLOB;
    fils BFILE :=BFILENAME('BFILE_DIR', 'a30.bmp');
    amt INTEGER;
    BEGIN
    insert into lob_tab values (1, empty_blob())
    returning c2 into lobd;
    DBMS_LOB.FILEOPEN(fils, dbms_lob.file_readonly);
    DBMS_LOB.LOADFROMFILE(lobd, fils, dbms_lob.getlength(fils));
    DBMS_LOB.FILECLOSE(fils);
    END;
    END-EXEC;
    EXEC SQL COMMIT WORK RELEASE;
    int o_error( action_str )
    char *action_str;
    int i;
    char error_str[150];
    EXEC SQL WHENEVER SQLERROR CONTINUE;
    for ( i = 0; i < sqlca.sqlerrm.sqlerrml; i++ )
    error_str[i] = sqlca.sqlerrm.sqlerrmc[i];
    error_str[i] = '\0';
    printf( "\nFailed with following Oracle error while %s:\n\n%s",
    action_str, error_str );
    EXEC SQL ROLLBACK WORK RELEASE;
    exit(1);

  • Nobody can solve this DBMS_LOB problem:

    I want to upload text file to ftp server but when i open file mcx.txt which is in e:\middle-east\ssm dmbs_lob.fileopen() function give error. edit e:\middle-east\ssm\mcx.txt; command also open this text file properly.
    ORA-22285: non-existent directory or file for FILEOPEN operation
    ORA-06512: at "SYS.DBMS_LOB", line 523
    ORA-06512: at "SCOTT.FTP", line 128
    ORA-06512: at "SCOTT.FTP", line 355
    ORA-06512: at line 7
    FUNCTION get_local_ascii_data (p_dir IN VARCHAR2,
    p_file IN VARCHAR2)
    RETURN CLOB IS
    l_bfile BFILE;
    l_data CLOB;
    BEGIN
    DBMS_LOB.createtemporary (lob_loc => l_data,
    cache => TRUE,
    dur => DBMS_LOB.call);
    l_bfile := BFILENAME(p_dir, p_file);
    DBMS_LOB.fileopen(l_bfile, DBMS_LOB.file_readonly);
    DBMS_LOB.loadfromfile(l_data, l_bfile, DBMS_LOB.getlength(l_bfile));
    DBMS_LOB.fileclose(l_bfile);
    RETURN l_data;
    END;

    Just for the sake of clarification ... What value are you specifying for p_dir variable?
    It should be a directory object created in the database.
    It can be created with a command like
    CREATE OR REPLACE DIRECTORY BFILE_DIR AS 'e:\middle-east\ssm';
    and the user who is going to call the function should have read access on this directory object which can be granted with a command like
    grant read on directory BFILE_DIR to FUNCTIONCALLINGUSER;
    I hope this helps with what you are trying
    Best Regards

Maybe you are looking for

  • Idvd plays some movie clips in a widescreen preview

    I can't figure out how to keep some clips from going into widescreen preview. They are marked to play in 4:3 mode. Of the 15 clips four play in widescreen preview in the preview mode. Help!

  • MD5 and Checksum Collisions ... A problem in APEX?

    There is a glut of information on the internet about the weaknesses of MD5 as a hash calculation. For example, <a href ="http://lookit.typepad.com/lookit/2006/10/a_new_demonstra.html">here</a>, here, and even a number of examples on how to easily gen

  • Locating user tables in an Oracle 11g database

    Excuse my ignorance on this subject But our company has an Oracle 11g database that drives one of our business applications. I am not an oracle admin and there is very little documentation on the application itself, however the application seems to h

  • Importing video through firewire fails to save video

    Hello, I am capturing video from a live event using the import feature of FCPX. I captured 14, one hour talks at a conference and on two of them, it failed to save the captured file to the disk. On both, I have pieces of the talk (7 minutes on one, 5

  • Printing a sapscript gives error .

    Hi I have created a new sapscript  to print a tax invoice .When i preview it i can see it fine . Also when in the print options  put locl and print it .It gets printed to the printer that i have allocated in my local . But when i change the print opt