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>

Similar Messages

  • 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

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

  • 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

  • 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

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

  • Help me to solve this Query

    Hi All,
    This is Sindhu..
    Here i got an error while excuting the following query related to BLOB data types in Oracle 11g.
    I have to compare two blobs, because my report needs that.
    for this..1st i ran the following package..
    @ORACLE_HOME/rdbms/admin/dbmslob.sql
    then i did this...
    declare
    src_lob BFILE := &src_lob;
    amount INTEGER := &amount;
    dest_offset INTEGER :=1;
    src_offset INTEGER :=1;
    dest_lob BLOB := &dest_lob;
    BEGIN
    dbms_lob.loadfromfile
    dest_lob,
    amount,
    src_lob,
    src_offset,
    dest_offset
    end;
    SQL> /
    Enter value for src_lob: 0820303623ECCFF8DCD9E0DFF11FDF1E1E7C3E6450E444E2E683A3D
    B03FF7B7CFF34FC24244724CF07CBDBC8EB80C034000436007E018801016B01FEFFFEFEFEFE0F7F0
    D07891FF198F1E9E1F304730C
    old 2: 2 src_lob BFILE := &src_lob;
    new 2: 2 src_lob BFILE := 0820303623ECCFF8DCD9E0DFF11FDF1E1E7C3E6450E444E2E
    683A3DB03FF7B7CFF34FC24244724CF07CBDBC8EB80C034000436007E018801016B01FEFFFEFEFEF
    E0F7F0D07891FF198F1E9E1F304730C;
    Enter value for amount: 18446744073709551615
    old 3: 3 amount INTEGER := &amount;
    new 3: 3 amount INTEGER := 18446744073709551615;
    Enter value for dest_lob: 8F2F1FE032E0E0C8C00CF91E2E1F0EDBDDF2D13292203E61614161
    80C0E689FFAEFFD7FEDF38FC3818013941F1C7C4C74FF3FF90F218000D1CAD9F89ED00E000024404
    D76DDFD6DF935F5B0E5C868E87
    old 6: 6 dest_lob BLOB := &dest_lob;
    new 6: 6 dest_lob BLOB := 8F2F1FE032E0E0C8C00CF91E2E1F0EDBDDF2D13292203E616
    1416180C0E689FFAEFFD7FEDF38FC3818013941F1C7C4C74FF3FF90F218000D1CAD9F89ED00E0000
    24404D76DDFD6DF935F5B0E5C868E87;
    ERROR:
    ORA-00972: identifier is too long
    SQL> declare
    2 lob_1 BLOB := &lob_1;
    3 lob_2 BLOB := &lob_2;
    4 amount INTEGER := 18446744073709551615;
    5 offset1 INTEGER :=1;
    6 offset2 INTEGER :=1;
    7 templob INTEGER;
    8 BEGIN
    9 templob :=dbms_lob.compare(lob_1,lob_2,amount,offset1,offset2);
    10 if (templob !=0 ) then
    11 dbms_output.put_line('Files Are Different');
    12 else
    13 dbms_output.put_line('Files Are Same');
    14 end if;
    15 end;
    16 /
    Enter value for lob_1: 0820303623ECCFF8DCD9E0DFF11FDF1E1E7C3E6450E444E2E683A3DB0
    3FF7B7CFF34FC24244724CF07CBDBC8EB80C034000436007E018801016B01FEFFFEFEFEFE0F7F0D0
    7891FF198F1E9E1F304730C
    old 2: lob_1 BLOB := &lob_1;
    new 2: lob_1 BLOB := 0820303623ECCFF8DCD9E0DFF11FDF1E1E7C3E6450E444E2E683A3DB0
    3FF7B7CFF34FC24244724CF07CBDBC8EB80C034000436007E018801016B01FEFFFEFEFEFE0F7F0D0
    7891FF198F1E9E1F304730C;
    Enter value for lob_2: 8F2F1FE032E0E0C8C00CF91E2E1F0EDBDDF2D13292203E6161416180C
    0E689FFAEFFD7FEDF38FC3818013941F1C7C4C74FF3FF90F218000D1CAD9F89ED00E000024404D76
    DDFD6DF935F5B0E5C868E87
    old 3: lob_2 BLOB := &lob_2;
    new 3: lob_2 BLOB := 8F2F1FE032E0E0C8C00CF91E2E1F0EDBDDF2D13292203E6161416180C
    0E689FFAEFFD7FEDF38FC3818013941F1C7C4C74FF3FF90F218000D1CAD9F89ED00E000024404D76
    DDFD6DF935F5B0E5C868E87;
    ERROR:
    ORA-00972: identifier is too long
    i do not know why i got this problem.. is there any error in my program..
    lobmaxsize=4GB
    how to increase the size of the data type.
    Please Help me.
    Thank You.

    Hi Sindhu,
    Your problem has not to with lob size.
    The error ORA-00972: identifier is too long
    tells you that
    0820303623ECCFF8DCD9E0DFF11FDF1E1E7C3E6450E444E2E683A3D
    B03FF7B7CFF34FC24244724CF07CBDBC8EB80C034000436007E018801016B01FEFFFEFEFEFE0F7F0
    D07891FF198F1E9E1F304730C
    becomes an identifier.
    Look into this for how to use substitution variables
    http://www.oracle.com/technology/support/tech/sql_plus/htdocs/sub_var.html
    If you don't have time to go through it all, I suggest you at least read section 2.
    This won't solve all your problems, but it should explain yur current ORA-00972.
    Regards
    Peter

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

  • Need help in highlighting the query text in document

    Hi, I am trying to load the files in the blob column and trying to create the text index on it.
    i need to query the blob column in the document table with a string, which needs to return the relevant documents with the query string highlighted with some color.
    Can you please help me with an example on the above.
    Thanks in advance.

    SCOTT@orcl_11gR2> -- table:
    SCOTT@orcl_11gR2> CREATE TABLE document_tab
      2    (document_col  BLOB)
      3  /
    Table created.
    SCOTT@orcl_11gR2> -- procedure to load documents:
    SCOTT@orcl_11gR2> CREATE OR REPLACE PROCEDURE load_document
      2    (p_dir  IN VARCHAR2,
      3       p_file IN VARCHAR2)
      4  AS
      5    v_blob       BLOB;
      6    v_bfile       BFILE;
      7  BEGIN
      8    INSERT INTO document_tab (document_col)
      9    VALUES (EMPTY_BLOB())
    10    RETURNING document_col INTO v_blob;
    11    v_bfile := BFILENAME (UPPER (p_dir), p_file);
    12    DBMS_LOB.FILEOPEN (v_bfile, DBMS_LOB.LOB_READONLY);
    13    DBMS_LOB.LOADFROMFILE (v_blob, v_bfile, DBMS_LOB.GETLENGTH (v_bfile));
    14    DBMS_LOB.FILECLOSE (v_bfile);
    15  END load_document;
    16  /
    Procedure created.
    SCOTT@orcl_11gR2> SHOW ERRORS
    No errors.
    SCOTT@orcl_11gR2> -- load documents (directory and files must be on server, not client):
    SCOTT@orcl_11gR2> CREATE OR REPLACE DIRECTORY my_dir AS 'c:\my_oracle_files'
      2  /
    Directory created.
    SCOTT@orcl_11gR2> BEGIN
      2    load_document ('my_dir', 'banana.pdf');
      3    load_document ('my_dir', 'english.doc');
      4    load_document ('my_dir', 'sample.txt');
      5  END;
      6  /
    PL/SQL procedure successfully completed.
    SCOTT@orcl_11gR2> -- confirm files were loaded:
    SCOTT@orcl_11gR2> SELECT DBMS_LOB.GETLENGTH (document_col)
      2  FROM   document_tab
      3  /
    DBMS_LOB.GETLENGTH(DOCUMENT_COL)
                              222824
                               22016
                                  60
    3 rows selected.
    SCOTT@orcl_11gR2> -- text index:
    SCOTT@orcl_11gR2> CREATE INDEX document_idx
      2  ON document_tab (document_col)
      3  INDEXTYPE IS CTXSYS.CONTEXT
      4  /
    Index created.
    SCOTT@orcl_11gR2> -- confirm files were indexed:
    SCOTT@orcl_11gR2> SELECT COUNT(*) FROM dr$document_idx$i
      2  /
      COUNT(*)
           319
    1 row selected.
    SCOTT@orcl_11gR2> -- function to return highlighted document:
    SCOTT@orcl_11gR2> CREATE OR REPLACE FUNCTION your_markup
      2    (p_index_name IN VARCHAR2,
      3       p_textkey    IN VARCHAR2,
      4       p_text_query IN VARCHAR2,
      5       p_plaintext  IN BOOLEAN  DEFAULT TRUE,
      6       p_tagset     IN VARCHAR2 DEFAULT 'HTML_DEFAULT',
      7       p_starttag   IN VARCHAR2 DEFAULT '*',
      8       p_endtag     IN VARCHAR2 DEFAULT '*',
      9       p_key_type   IN VARCHAR2 DEFAULT 'ROWID')
    10    RETURN          CLOB
    11  AS
    12    v_clob          CLOB;
    13  BEGIN
    14    CTX_DOC.SET_KEY_TYPE (p_key_type);
    15    CTX_DOC.MARKUP
    16        (index_name => p_index_name,
    17         textkey    => p_textkey,
    18         text_query => p_text_query,
    19         restab     => v_clob,
    20         plaintext  => p_plaintext,
    21         tagset     => p_tagset,
    22         starttag   => p_starttag,
    23         endtag     => p_endtag);
    24    RETURN v_clob;
    25  END your_markup;
    26  /
    Function created.
    SCOTT@orcl_11gR2> SHOW ERRORS
    No errors.
    SCOTT@orcl_11gR2> -- query that returns highlighted document:
    SCOTT@orcl_11gR2> VARIABLE string VARCHAR2(100)
    SCOTT@orcl_11gR2> EXEC :string := 'test AND demonstration'
    PL/SQL procedure successfully completed.
    SCOTT@orcl_11gR2> SELECT your_markup ('document_idx', ROWID, :string)
      2           AS highlighted_text
      3  FROM   document_tab
      4  WHERE  CONTAINS (document_col, :string) > 0
      5  /HIGHLIGHTED_TEXT
    This is a test document for demonstration of highlighting.
    1 row selected.
    SCOTT@orcl_11gR2>

  • Need help on Reading BFILE, CLOB

    Hi all
    i am using Linux fedora 4
    i have created a directory
    create directory clob_dir as '/db10g/my_dir';
    and created a table from examples of a book i have
    CREATE TABLE BFILE_DOC
    (     ID INTEGER,
         BFILE_CLMN BFILE
    And a procedure to read a text file contents
    CREATE OR REPLACE
    PROCEDURE FILE_EXAMPLE (id_var in number) AS
    SRC_BFILE_VAR BFILE;
    DIR_ALIAS_VAR VARCHAR2(50);
    FILENAME_VAR VARCHAR2(50);
    CHUNK_SIZE_VAR INTEGER;
    LENGTH_VAR INTEGER;
    CHARS_READ_VAR INTEGER;
    DEST_CLOB_VAR NCLOB;
    AMOUNT_VAR INTEGER := 80;
    DEST_OFFSET_VAR INTEGER := 1;
    SRC_OFFSET_VAR INTEGER := 1;
    CHAR_BUFFER_VAR VARCHAR2(160);
    BEGIN
    SELECT BFILE_CLMN
    INTO SRC_BFILE_VAR
    FROM BFILE_DOC
    WHERE ID = id_var;
    DBMS_LOB.CREATETEMPORARY(DEST_CLOB_VAR, TRUE);
    IF (DBMS_LOB.FILEEXISTS(SRC_BFILE_VAR) = 1) THEN
    IF (DBMS_LOB.FILEISOPEN(SRC_BFILE_VAR) = 0) THEN
    DBMS_LOB.FILEOPEN(SRC_BFILE_VAR);
    DBMS_LOB.FILEGETNAME(SRC_BFILE_VAR,
    DIR_ALIAS_VAR,
    FILENAME_VAR);
    DBMS_OUTPUT.PUT_LINE('DIRECTORY NAME: ' || DIR_ALIAS_VAR);
    DBMS_OUTPUT.PUT_LINE('FILE NAME : ' || FILENAME_VAR );
    CHUNK_SIZE_VAR := DBMS_LOB.GETCHUNKSIZE(DEST_CLOB_VAR);
    DBMS_OUTPUT.PUT_LINE('CHUNK SIZE : ' || CHUNK_SIZE_VAR);
    LENGTH_VAR := DBMS_LOB.GETLENGTH(SRC_BFILE_VAR);
    DBMS_OUTPUT.PUT_LINE('LENGTH : ' || LENGTH_VAR);
    CHARS_READ_VAR := 0;
    WHILE (CHARS_READ_VAR < LENGTH_VAR) LOOP
    IF (LENGTH_VAR - CHARS_READ_VAR < AMOUNT_VAR) THEN
    AMOUNT_VAR := LENGTH_VAR - CHARS_READ_VAR;
    END IF;
    DBMS_LOB.LOADFROMFILE(DEST_CLOB_VAR, SRC_BFILE_VAR,
    AMOUNT_VAR, DEST_OFFSET_VAR,
    SRC_OFFSET_VAR + CHARS_READ_VAR);
    DBMS_LOB.READ(DEST_CLOB_VAR,
    AMOUNT_VAR,
    SRC_OFFSET_VAR,
    CHAR_BUFFER_VAR);
    DBMS_OUTPUT.PUT_LINE('CHAR BUFFER VAR:' || CHAR_BUFFER_VAR);
    CHARS_READ_VAR := CHARS_READ_VAR + AMOUNT_VAR;
    END LOOP;
    END IF ;
    END IF;
    DBMS_LOB.FILECLOSE(SRC_BFILE_VAR);
    DBMS_LOB.FREETEMPORARY(DEST_CLOB_VAR);
    END FILE_EXAMPLE;
    then i post a text file ( the size is 456.5 KB) in MY_DIR FOLDER
    the i inserted the informatin in that table
    INSERT INTO BFILE_DOC( ID , BFILE_CLMN)
    VALUES (1, BFILENAME('CLOB_DIR', 'abc.txt'));
    Then i called the procedure
    SQL> call file_example(1);
    here what i got
    CHAR BUFFER VAR:噁‰㐳㔠〵㨲㔠††††††††††††††䥓单䕄㨠〷⼳〯〶†䩅䐠䉁卅†ਠⴭⴭⴭⴭ
    CHAR BUFFER VAR:†††ਠ㈹䙒††††㜷䈠⁇噁‰㔳㔠⁆剁‰†䥓单䕄㨠〷⼳〯〶†䩅䐠䉁卅†ਠⴭⴭⴭⴭ
    CHAR BUFFER VAR:㜰㔠〱㨳〠††††††††††††††††䥓单䕄㨠〷⼳〯〶†䩅䐠䉁卅†ਠⴭⴭⴭⴭ
    CHAR BUFFER VAR:†ਠ††††††䵁剉呉䴠䡏呅䰠††††††䥓单䕄㨠〷⼳〯〶†䩅䐠䉁卅†ਠⴭⴭⴭⴭ
    CHAR BUFFER VAR:††††〶㨵㔠〹㨵㔠〶㨵㔠⁆剁†㜷㨴〠ਠ†䥓单䕄㨠〷⼳〯〶†䩅䐠䉁卅†ਠⴭⴭⴭⴭ
    CHAR BUFFER VAR:〲䵏†‱㠶†㜷䈠⁆剁‱㈴㔠⁇噁‱㐰〠〱㨱†䥓单䕄㨠〷⼳〯〶†䩅䐠䉁卅†ਠⴭⴭⴭⴭ
    call file_example(1)
    ERROR at line 1:
    ORA-20000: ORU-10027: buffer overflow, limit of 1000000 bytes
    ORA-06512: at "SYS.DBMS_OUTPUT", line 32
    ORA-06512: at "SYS.DBMS_OUTPUT", line 97
    ORA-06512: at "SYS.DBMS_OUTPUT", line 112
    ORA-06512: at "SCOTT.FILE_EXAMPLE", line 51
    and here a sample of the content in the text file if i open it with text editor
    1 MO REPORT AT 12:35 EFFECTIVE SEP 04-SEP 18
    1 SA
    DAY FLT: EQP DEPARTS ARRIVES BLK. BLK: DUTY CR: LAYOVER
    MO 034 744 JED 1405 RUH 1540 01:35
    SAHARA AIRPORT HOTEL 01:35 03:35 01:35 RUH 19:05
    TU 1905 AB3 RUH 1045 TIF 1215 01:30
    TU 1904 AB3 TIF 1315 RUH 1440 01:25
    TU 1783 AB3 RUH 1540 GIZ 1730 01:50
    TU 1777 AB3 GIZ 1820 JED 1930 01:10
    05:55 10:45 05:55
    CREDIT_HRS: 07:30 BLK_HRS: 07:30 LDGS: 5 TAFB 31:25
    2 MO REPORT AT 21:25 EFFECTIVE SEP 04-SEP 18
    1 SA
    DAY FLT: EQP DEPARTS ARRIVES BLK. BLK: DUTY CR: LAYOVER
    MO 113 77B JED 2255 LHR 0520 06:25
    HILTON LONDON KENSIN 06:25 08:25 06:25 LHR 38:25
    WE 116 77B LHR 1945 JED 0150 06:05
    06:05 08:05 06:05
    CREDIT_HRS: 12:30 BLK_HRS: 12:30 LDGS: 2 TAFB 52:55
    ( the text file has more than 6000 line)
    notes:
    my ENV file ( bash_profile)
    # .db10g
    # Get the aliases and functions
    if [ -f ~/.bashrc ]; then
         . ~/.bashrc
    fi
    # User specific environment and startup programs
    PATH=$PATH:$HOME/bin; export PATH
    ORACLE_BASE=/db10g/app/oracle; export ORACLE_BASE
    ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1; export ORACLE_HOME
    ORACLE_SID=orcl; export ORACLE_SID
    ORACLE_TERM=xterm; export ORACLE_TERM
    PATH=/usr/sbin:$PATH; export PATH
    PATH=$ORACLE_HOME/bin:$PATH; export PATH
    NLS_LANG=AMERICAN_AMERICA.AL32UTF8; export NLS_LANG
    LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib; export LD_LIBRARY_PATH
    CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib; export CLASSPATH
    unset USERNAME
    The charset of the database is set to AL32UTF8. during the installtion time
    The questions :
    Whats wrong here?
    why i can not read the content of the txt file as it is ?
    i tried this issue in windows xp with SQL*PLUS, i got the same chars but no error.
    what to do to avoid the errors and to see the text file as its?
    how to load the content of the text file to CLOB Column if it is larger than 4000?
    thanks

    set serveroutput on
    BEGIN
    -- Enable DBMS_OUTPUT and set the buffer size. The buffer size can be between 1 and 1,000,000
    dbms_output.enable(1000000);
    END;
    check the datatypes of the supplied packages from the doumentation;
    dbms_output.put_line(item VARCHAR2);
    dbms_lob.read(
    lob_loc IN BLOB,
    amount IN OUT NOCOPY INTEGER,
    offset IN INTEGER,
    buffer OUT RAW);
    also sample usage of the package will help -> http://psoug.org/reference/dbms_lob.html

  • Help:- Store Word file in database using blob

    Hai all,
    i want to store word document in database and reterieve from database but i don't have any idea i heared about blob but i don't know how to make it any one have source code or example form pls send me
    email: [email protected]

    Hello,
    First of all, you have got to be granted the privilege to read and write to the file system, this is a must to use BFile read access.
    A global function bfilename returns a bfile taking the file path as an argument is needed to construct a blob object through dbms_lob.loadfromfile.
    A very helpful example I found on orafaq follows:Create a link to the directory where the file to load in the blob is
    (connect as system then grant read privilege to your user):
    create or replace directory blob_dir as 'C:\Documents';
    Custom the following procedure that I copied from a Thread
    create or replace procedure blob_ins(p_id in number, p_filename in
    varchar2) as
    l_bfile bfile;
    l_blob blob;
    begin
    insert into blob_test(p_id, empty_blob())
    returning blob_file into l_blob;
    l_bfile := bfilename('BLOB_DIR', p_filename);
    dbms_lob.fileopen(l_bfile);
    dbms_lob.loadfromfile(l_blob, l_bfile, dbms_lob.getlength(l_bfile));
    dbms_lob.fileclose(l_bfile);
    commit;
    return;
    end blob_ins;
    You can use UTL_FILE package in another way, but this is much more safe;
    Have Fun
    Hossam Al Din

  • 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

  • Need some help extracting images from blobs...

    hi,
    I want to upload a image to a oracle blob and then download it and display it into a browser using jsp. I am new to java as will as oracle and doing a project for the first time. I have searched the internet and found out some links:
    http://fdegrelle.over-blog.com/article-992927-6.html
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:232814159006
    http://forums.devx.com/archive/index.php/t-142347.html
    I feel the solutions given are very vogue and also tried the solutions posted in java forums itself. I would like to have simple example, step by step explanation for uploading an image into a oracle blob,download the image and display it in a browser using a jsp so that i can understand the concepts.
    Thank you SUN and JAVA PROGRAMMERS.

    thanks yogee,
    The creators of these examples have assumed that the developers are advanced users. I am not an advanced user. I am not even a intermediate user.
    1.....................................I understood this(Create Table)
    create table demo
    ( id        int primary key,
      theBlob    blob
    )/2...................................I understood this too(I suppose we are mapping the folder path)
    create or replace directory my_files as '/export/home/tkyte/public_html';3..................................I understood this too(upload the file into the blob)
    declare
        l_blob    blob;
        l_bfile    bfile;
    begin
        insert into demo values ( 1, empty_blob() )
        returning theBlob into l_blob;
        l_bfile := bfilename( 'MY_FILES', 'aria.gif' );
        dbms_lob.fileopen( l_bfile );
        dbms_lob.loadfromfile( l_blob, l_bfile,
                                   dbms_lob.getlength( l_bfile ) );
        dbms_lob.fileclose( l_bfile );
    end;
    /4..................................we are creating a package here. I got it.
    create or replace package image_get
    as
        procedure gif( p_id in demo.id%type );
    end;
    /5...................................we are suppose to use this to extract the file from the blob. But where does this get stored?
    create or replace package body image_get
    as
    procedure gif( p_id in demo.id%type )
    is
        l_lob    blob;
        l_amt    number default 30;
        l_off   number default 1;
        l_raw   raw(4096);
    begin
        select theBlob into l_lob
            from demo
             where id = p_id;
            -- make sure to change this for your type!
        owa_util.mime_header( 'image/gif' );
            begin
               loop
                  dbms_lob.read( l_lob, l_amt, l_off, l_raw );
                  -- it is vital to use htp.PRN to avoid
                  -- spurious line feeds getting added to your
                  -- document
                  htp.prn( utl_raw.cast_to_varchar2( l_raw ) );
                  l_off := l_off+l_amt;
                  l_amt := 4096;
               end loop;
            exception
               when no_data_found then
                  NULL;
            end;
    end;
    end;
    /6...............................Execute the procedure!
    exec image_get
    7..................................What after this step?
    I do not know servlets. I only know JSP? If you can please write a simple servlet to access the data and display it on the browser
    Sample servlet code is in the link as a last user comment. I couldn't understand head or tail.
    http://forums.devx.com/archive/index.php/t-142347.html
    I appreciate your help.
    Message was edited by:
    ted_anderson

Maybe you are looking for

  • Expense reports with respect to posting date

    Hi Folks, Kindly let us know if any statndard reports are available to extract trip details with respect to the trip posting date (prrw). Thanks, Nandagopal C

  • Setting the permissions to the personal folder in KM

    Hi steffi, I have created the KM iview using the path  /~alias~/userhome/<user.id>/Personal Documents and i have assigned to one custom role  and the newly created folder is visible to only the particular loggedin user. Now my requirement is Folder w

  • Help need in Update query

    Hi friends, os id ot_id ot ot os_id I will be having more records for ot_id in the table os, now i want to update the max(id) from os for each ot_id in that table to the os_id in the ot table help me in this please

  • Canon 7D RAW format

    iPhoto does not recognize my new camera's files. How long does it take Apple to update it's programs for new cameras??

  • Creating iPhoto Partition? Or Cloning App?

    Hi all, I would really like to know if it's possible, and if it is HOW, to create a partition in my current iPhoto, or in fact how to clone the entire application, but w/o all my existing pictures copied over. I hope that made sense... I collect fash