Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> Re: Insert data into LOB column

Re: Insert data into LOB column

From: Marin Dimitrov <marin_at_sirma.bg>
Date: Wed, 07 Feb 2001 01:11:43 -0800
Message-ID: <F001.002AD4B1.20010206234028@fatcity.com>

>
> I am new to working with LOBs. I want to insert data (through SQL or
PL/SQL)
> into a table that looks like this:
>
> column1 varchar2(100)
> column2 BLOB
> column3 number
>
> How can I insert data into that table directly?
>
> insert into table (column1, colum2, column3) values ('sample text', ?????,
> 12345);
>
> The BLOB can be a TXT-file or GIF-picture or bmp-picture. The file is
> locally stored on the hard drive.
>

I haven't done this with PL/SQL but peeking into the docs it seems that the u should follow the steps:

  1. create a directory alias with CREATE DIRECTORY in the DB for a directory on the server filesystem
  2. execute your insert statement but replace "?????" with EMPTY_BLOB()
  3. modify & execute the following procedure (copy&paste) from the "Oracle8i Application Developer's Guide - Large Objects (LOBs) " chapter of the docs. The procedure reads a BFILE from the directory created in step 1 and copies its content in the "Frame" LOB from the "Multimedia_tab" table

/* Note that the example procedure loadLOBFromBFILE_proc is not part of the

   DBMS_LOB package: */
CREATE OR REPLACE PROCEDURE loadLOBFromBFILE_proc IS

   Dest_loc       BLOB;
   Src_loc        BFILE := BFILENAME('FRAME_DIR', 'Washington_frame');
   Amount         INTEGER := 4000;

BEGIN
   SELECT Frame INTO Dest_loc FROM Multimedia_tab

      WHERE Clip_ID = 3 FOR UPDATE;
   /* Opening the source BFILE is mandatory: */    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);
   COMMIT;
END; If u're familiar with Java/JDBC it's a lot easier to work with LOBs. Anyways, the documentation should be sufficient to get the thing done.

hth,

    Marin



"When someone is seeking, it happens quite easily that he only sees the thing that he is seeking; that he is unable to find anything, unable to absorb anything, because he is only thinking of the thing he is seeking, because he is obsessed with his goal. Seeking means: to have a goal; but finding means: to be free, to be receptive, to have no goal. ..."
                                Herman Hesse, "Siddhartha"



-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: Marin Dimitrov
  INET: marin_at_sirma.bg

Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).
Received on Wed Feb 07 2001 - 03:11:43 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US