Oracle & BLOB/LONG RAW

Hi everybody,
I need to store binary data (> 32K) in an oracle BLOB field, respectivly commit the data to an oracle PL/SQL stored procedure.
First I tried to use LONG RAW, but failed to commit more than 32K of data. This seems to be a documented problem, you can store 2GBs in an LONG RAW field, but PL/SQL can only store 32K in an LONG RAW variable.
Then I tried to switch from LONG RAW to BLOB (both the field in the table and the in variable in the stored procedure) but it seems to be very complicated to use BLOB fields with JDBC.
I've found example for a plain INSERT. First execute an INSERT with an empty BLOB, then make an SELECT FOR UPDATE on the row, obtain the reference to the BLOB-Object, alter the BLOB-Object and create an UPDATE-Statement with it.
I've not tried this yet, but according to various web sites it should work.
The problem is, that it does not solves the problem how to commit a BLOB value to a PL/SQL stored procedure.
Does anyone knows a solution?
Thx and regards,
Robert

Hi,
thx for your answer.
That's the solution I described (INSERT, SELECT, UPDATE) and only works with Statements.
But I think I've already found a mistake of mine, I have to try this today.
I already succeeded in creating a BLOB-Object without obtaining it from a resultset, the constructor is not documented but it exists, it looks like BLOB( OracleConnection, byte[] ).
I think I can commit the BLOB to the stored procedure but it won't be a valid BLOB locator.
What I've not tried yet and what I think migth be the solution is creating the valid BLOB locator inside the stored procedure using the PL/SQL BLOB methods.
Sounds simple but for some reasons I have not thougth about it yet. :-)
I'll report the result here if somebody else is interested in the issue. :o)
Thx and regards,
Robert

Similar Messages

  • BLOB-LONG RAW

    Can you give e some guidance on behaviour of LONG RAW and
    BLOB with ODBC. In my application I am using a BLOB field but ODBC is not
    allowing me to insert more than 4k binary data. Then I used LONG RAW for
    that field but now its not working properly. If you know SQLGetData is an
    ODBC API used. It is behaving differently for LONG RAW& BLOB which I thnk
    is root cause. If anyone out there could help me, I will be really obliged.
    1) How to insert more than 4k in BLOB using ODBC (driver which comes with
    Oracle 8i Enterprise edition)
    2) Difference in behaviiour of ODBC SQLGetData for BLOB & LONG RAW

    Hi,
    thx for your answer.
    That's the solution I described (INSERT, SELECT, UPDATE) and only works with Statements.
    But I think I've already found a mistake of mine, I have to try this today.
    I already succeeded in creating a BLOB-Object without obtaining it from a resultset, the constructor is not documented but it exists, it looks like BLOB( OracleConnection, byte[] ).
    I think I can commit the BLOB to the stored procedure but it won't be a valid BLOB locator.
    What I've not tried yet and what I think migth be the solution is creating the valid BLOB locator inside the stored procedure using the PL/SQL BLOB methods.
    Sounds simple but for some reasons I have not thougth about it yet. :-)
    I'll report the result here if somebody else is interested in the issue. :o)
    Thx and regards,
    Robert

  • How can i read a stored picture in oracle Long Raw datatype? blob or clob?

    How can i read a stored picture in oracle Long Raw datatype? Like a blob or clob?....i am using jdk 1.3
    This is because...i tried to read it like a blob but i obtain a exception...about Type of column no valid......but the column exist....and it contains the long raw datatype of the pictures.....this is my code:
    import java.sql.*;
    import java.io.*;
    import java.util.*;
    import oracle.jdbc.driver.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.InputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.OutputStream;
    import java.sql.Connection;
    import java.sql.Statement;
    import java.sql.ResultSet;
    import java.sql.DriverManager;
    import oracle.sql.BLOB;
    import oracle.sql.BLOB.*;
    import oracle.jdbc.driver.*;
    import java.sql.*;
    class rec_ima1
    public static void main(String h[])
    Connection con = null;
    Blob bl;
    final ImageIcon image1;
    JPanel photo;
    try
    Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
    con= DriverManager.getConnection("jdbc:oracle:thin:@123.3.12.213:1521:db_name","user","password");
    String query = "Select * from pictures where ID = '18840'";
    Statement stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery( query );
    if (!rs.next())
    System.out.println("Empty Result Set");
    bl = rs.getBlob(5);
    if (bl == null) {
    System.out.println("Null Blob");
    return;
    InputStream is = bl.getBinaryStream();
    int imageLength = (int) bl.length();
    System.out.println(imageLength);
    System.out.println(bl.length());
    byte[] imageData = new byte [imageLength];
    is.read(imageData, 0, imageLength);
    image1 = new ImageIcon(imageData);
    photo = new JPanel() {
    public void paint(Graphics g){
    g.setColor(Color.lightGray);
    g.drawImage(image1.getImage(), 0, 0, this);
    } catch (Exception e) {
    e.printStackTrace();
    Now i tried using clob:
    import java.sql.*;
    import java.io.*;
    import java.util.*;
    import oracle.jdbc.driver.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.InputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.OutputStream;
    import java.sql.Connection;
    import java.sql.Statement;
    import java.sql.ResultSet;
    import java.sql.DriverManager;
    import oracle.sql.CLOB;
    import oracle.sql.CLOB.*;
    import oracle.jdbc.driver.*;
    import java.sql.CallableStatement;
    class rec_ima4
    public static void main(String h[])
    Connection con = null;
    Clob cl;
    JPanel photo;
    try
    Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
    con= DriverManager.getConnection("jdbc:oracle:thin:@123.3.12.213:1521:db_name","user","password");
    con.setAutoCommit (false);
    String query = "Select * from pictures where ID = '18840'";
    Statement stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery( query );
    while (rs.next()) {
    oracle.sql.CLOB clob = (CLOB) rs.getObject(5); //line 47
    } catch (Exception e) {
    e.printStackTrace();
    This is the runtime exception:
    java.lang.ClassCastException: [B
    at rec_ima4.main(rec_ima4.java:47)

    Thanks by answering to me......
    Well....i did that....but what is ImageIO?....
    I declared a ImageIcon imageIO, but this give me the following:
    rec_ima3.java:49: cannot resolve symbol
    symbol : class BufferedImage
    location: class rec_ima3
    BufferedImage bi = ImageIO.read(bInput);
    ^
    rec_ima3.java:49: cannot resolve symbol
    symbol : variable ImageIO
    location: class rec_ima3
    BufferedImage bi = ImageIO.read(bInput);
    ^
    What classes i have to import?.....what is ImageIO?
    Thanks

  • Issue with Oracle LONG RAW data type

    Hi All,
    I am facing some issues with Oracle LONG RAW DATA Type.
    We are using Oracle 9IR2 Database.
    I got a table having LONG RAW column and I need to transfer the same into another table having LONG RAW column.
    When I tried using INSERT INTO SELECT * command (or) CREATE TABLE as select * , it is throwing ORA-00997: illegal use of LONG datatype.
    I have gone through some docs and found we should not use LONG RAW using these operations.
    So I did some basic PLSQL block given below and I was able to insert most of the records. But records where the LONG RAW file is like 7O kb, the inserting is faliling.
    I tried to convert LONG RAW to BLOB and again for the record where the LONG RAW is big in size I am getting (ORA-06502: PL/SQL: numeric or value error) error.
    Appreciate if anyone can help me out here.
    DECLARE
    Y LONG RAW;
    BEGIN
    FOR REC IN (SELECT * FROM TRU_INT.TERRITORY WHERE TERRITORYSEQ=488480 ORDER BY TERRITORYSEQ ) LOOP
    INSERT INTO TRU_CMP.TERRITORY
    BUSINESSUNITSEQ, COMPELEMENTLIFETIMEID, COMPONENTIMAGE, DESCRIPTION, ENDPERIOD, GENERATION, NAME, STARTPERIOD, TERRITORYSEQ
    VALUES
    REC.BUSINESSUNITSEQ, REC.COMPELEMENTLIFETIMEID, REC.COMPONENTIMAGE, REC.DESCRIPTION, REC.ENDPERIOD, REC.GENERATION, REC.NAME,
    REC.STARTPERIOD, REC.TERRITORYSEQ
    END LOOP;
    END;
    /

    Maddy wrote:
    Hi All,
    I am facing some issues with Oracle LONG RAW DATA Type.
    We are using Oracle 9IR2 Database.
    I got a table having LONG RAW column and I need to transfer the same into another table having LONG RAW column.
    When I tried using INSERT INTO SELECT * command (or) CREATE TABLE as select * , it is throwing ORA-00997: illegal use of LONG datatype.
    I have gone through some docs and found we should not use LONG RAW using these operations.
    So I did some basic PLSQL block given below and I was able to insert most of the records. But records where the LONG RAW file is like 7O kb, the inserting is faliling.
    I tried to convert LONG RAW to BLOB and again for the record where the LONG RAW is big in size I am getting (ORA-06502: PL/SQL: numeric or value error) error.
    Appreciate if anyone can help me out here.
    DECLARE
    Y LONG RAW;
    BEGIN
    FOR REC IN (SELECT * FROM TRU_INT.TERRITORY WHERE TERRITORYSEQ=488480 ORDER BY TERRITORYSEQ ) LOOP
    INSERT INTO TRU_CMP.TERRITORY
    BUSINESSUNITSEQ, COMPELEMENTLIFETIMEID, COMPONENTIMAGE, DESCRIPTION, ENDPERIOD, GENERATION, NAME, STARTPERIOD, TERRITORYSEQ
    VALUES
    REC.BUSINESSUNITSEQ, REC.COMPELEMENTLIFETIMEID, REC.COMPONENTIMAGE, REC.DESCRIPTION, REC.ENDPERIOD, REC.GENERATION, REC.NAME,
    REC.STARTPERIOD, REC.TERRITORYSEQ
    END LOOP;
    END;
    /below might work
    12:06:23 SQL> help copy
    COPY
    Copies data from a query to a table in the same or another
    database. COPY supports CHAR, DATE, LONG, NUMBER and VARCHAR2.
    COPY {FROM database | TO database | FROM database TO database}
                {APPEND|CREATE|INSERT|REPLACE} destination_table
                [(column, column, column, ...)] USING query
    where database has the following syntax:
         username[/password]@connect_identifier

  • Can we use BLOB instead of LONG RAW in JMSStore

    (Oracle 9i, Weblogic 8.1.2)
              We are putting in place a Dataguard environment (or standby database). In such environment, prod data is copied to another database in 'pseudo' real time. Unfortunately some 'old' datatypes are not supported by Dataguard. In JMS tables %JMSSTORE, the field RECORD is defined as LONG RAW and LONG RAW is one of the unsupported datatypes.
              Can we alter those tables in order to use BLOB instead of LONG RAW ?
              Regards,
              Bao Nguyen
              

    Hi Bao,
              Answers in-line:
              Bao Nguyen wrote:
              > (Oracle 9i, Weblogic 8.1.2)
              >
              > We are putting in place a Dataguard environment (or standby database). In such environment, prod data is copied to another database in 'pseudo' real time. Unfortunately some 'old' datatypes are not supported by Dataguard. In JMS tables %JMSSTORE, the field RECORD is defined as LONG RAW and LONG RAW is one of the unsupported datatypes.
              >
              > Can we alter those tables in order to use BLOB instead of LONG RAW ?
              Not supported in 8.1. A supported Oracle BLOB capability will be
              available in the next release. I can think of two
              possible work-arounds:
              (1) The following might work, but is not currently supported by
              BEA: Manually create the table with a BLOB type and use
              an Oracle OCI or BEA type IV driver. Definitely do NOT use
              an Oracle thin driver, as data corruption may result.
              (2) I recall that another customer had a replication product
              they were able to get working with LONG RAW by modifying
              the table definition so that the table's handle index was a primary key.
              I do not remember the name of the product.
              (The latter modification is supported for certain releases
              now - but I think this usage must be confirmed with customer support.)
              Tom
              >
              > Regards,
              >
              > Bao Nguyen
              >
              

  • 6i to 9i conversion OLE container stored in a LONG RAW column to BLOB

    I need to automate the migration of data stored in a long raw column to a blob column. The objects were stored in the long raw column using an Oracle Forms 6i OLE container. There is also multiple object types stored in the column, ie (word, excel, images, but mostly pdf's). I have looked at the webutil package but cannot figure out how to read the long raw column since ole containers are obsolete in 9i. I have a lot of records that need migrating and need help.
    Thanks,
    J. Broome
    [email protected]

    It doesn't appear that I am able to attach the PDF files.  Can you supply your email (or I can supply mine) so I can send you the three files:
    1.)  A good PDF (manually extracted from our old application)
    2.)  Dump of the same PDF file (includes header/footer info)
    3.)  A partially fixed PDF file (but some of the pictures / pages are cut off - specifically pages 3,5,9,10,12,14)
    The way that we have tried to fix the file (in example 3 above) is the following:
    a.)  Find the First Occurrence of "%PDF-"
    b.)  Find the Last Occurrence of "%%EOF"
    c.)  if the first "%PDF-" is found AND the last "%%EOF" is found, then
       i.)  Remove all data before the first %PDF-
       ii.)  Remove all data after the last %%EOF
    Let me know if you need any other information.
    Thanks,
    Mike

  • Migrating LONG RAW to BLOB and optimizing extent size

    Hi all,
    I got a quite fragmented table with a LONG RAW column I want to migrate to BLOB and defragment.
    DB version is Oracle9i Release 9.2.0.4.0 and this is a production environment.
    I know MOVE and/or CTAS are not possible with LONG RAW columns
    So, how can I do that? Is ALTER TABLE MODIFY the only possibility to migrate from LOING RAW to BLOB?
    Since ALTER TABLE MODIFY will lock the whole table preventing any DML operation, I need at least a rough estimate of the time needed for this operation. How can I do that?
    Since this table is quite fragmented, I also want to rebuilt it using a different extent size.
    I think I should issue a ALTER TABLE MOVE... after having performed the "ALTER TABLE MODIFY".
    Can I do something better to minimize unavailability to DML operations?
    thanks,
    andrea

    Hi,
    Is this an OCCI question?
    I don't see that "to_blob" is documented anywhere. The "to_lob" function can be used to convert long raw columns, but its use is pretty specific and certainly not for general query use.
    Regards,
    Mark
    EDIT1: Well, my local documentation set does not have "to_blob" in it at all. However, it is in the 11.1 SQL Language Reference on OTN:
    http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/functions186.htm#sthref2358
    Despite the fact that the documentation mentions "long raw" the function appears to only work with "raw" data in my 11.1 tests.
    What's your goal here?
    Edited by: Mark Williams on Jun 8, 2009 7:15 PM

  • Converstion Long raw to BLOB

    Hello All,
    I am using Oracle 10g,
    I need to alter a table which have a Long row data type column, i want to modify the data type of this column to BLOB.
    This table contains data, does this alteration affect the data of the table in any way?
    Regards,

    Any information ? if the alteration of the LONG RAW data type to BLOB affect the existing data ?
    Thanks in advance ,

  • Long raw to blob

    Hi
    I am working on Pl/Sql scrpit to transfer data/images from one Oracle 8i DB to another.
    The images to be transfered are in Long Raw but need to populate a column in BLOB.
    Any ideas how to convert?

    http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:13213885403654

  • BLOB or LONG RAW ?

    Hi,
    Who can explain to me what differences are between BLOB Format
    and LONG RAW format ?? Which between the twice is better to store
    picture and sound in a Oracle database.
    It's for a application project in Developer V6 on the web.
    Thanks,
    Bart
    null

    Bart (guest) wrote:
    : Hi,
    : Who can explain to me what differences are between BLOB
    Format
    : and LONG RAW format ?? Which between the twice is better to
    store
    : picture and sound in a Oracle database.
    : It's for a application project in Developer V6 on the web.
    : Thanks,
    : Bart
    I would recommend to use blobs. This are the new datatypes in
    Oracle8, they can store up to 4 GB (lang raw 2 GB); in addition,
    lang raw are only for backward compatibility (see you oracle 8
    documentation). Furthermore, you can use the dbms_lob package on
    LOB datatypes to manipulate lob data in the database.
    peter
    null

  • BLOB vs. LONG RAW - size restrictions?

    In the Oracle Lite 10g release notes, it states...
    1.3.1 BLOB Support in the Oracle Lite Database
    Most of the data is stored in the Oracle Lite database file with an ODB extension; any BLOB objects—either binary or character—and the indexes are stored in a file with an OBS extension.
    Because BLOB data and indexes are stored in an OBS file, there is no limit for BLOB data or indexes. The limitation for BLOB data and indexes is the space limitations of the operating system or 16 terabytes. There still exists a 4 GB limitation for the ODB file; however, this is not as much of an issue now that BLOB data can be stored in the OBS files.
    I have an application that stores "blobs" in a table using the LONG RAW data type. Is the data stored in columns of type LONG RAW stored in the ODB file (which is limited to 4 GB) or the OBS file?
    Thanks!
    Kelly

    Long columns are limited to 2Gb lenght and are stored inline.
    Ref. Oracle® Database Reference
    10g Release 2 (10.2)
    Part Number B14237-02
    ~ Madrid

  • PLSQL 을 사용해서 LONG RAW 를 BLOB 으로 바꾸는 방법

    제품 : PL/SQL
    작성날짜 : 2002-10-16
    PLSQL 을 사용해서 LONG RAW 를 BLOB 으로 바꾸는 방법
    ======================================
    PURPOSE
    PLSQL 을 사용해서 LONG/LONG RAW 를 BLOB/CLOB 으로 바꾸는 방법을
    예제를 통해 알아봅니다.
    만일 Oracle 9i v9.x 를 이용하는 경우에는 다음 명령을 사용하실 수 있습니다.
    ALTER TABLE 'TABLE with LONG column' MODIFY ('LONG column' CLOB)
    또는
    ALTER TABLE 'TABLE with LONG RAW column' MODIFY ('LONG RAW column' BLOB)
    Example
    Example #1
    Example #1 은 LONG column 에 64k 이하의 data 가 있을 경우
    PL/SQL 을 이용해서 BLOB 으로 바꾸는 예제 입니다.
    -- table 을 drop 합니다.
    drop table traw;
    drop table tblob
    -- table 을 생성합니다.
    create table traw (n1 number , l1 long raw);
    create table tblob (n1 number , l1 blob);
    --- clob 도 사용 가능합니다.
    -- table 에 insert 합니다.
    begin
    for i in 1..10 loop
    insert into traw values (i,utl_raw.cast_to_raw(rpad(to_char(i),60,'&')));
    insert into tblob values (i,empty_blob());
    end loop;
    end;
    declare
    lobloc blob;
    buffer long raw(32000);
    amount number ;
    offset number := 1;
    begin
    for rec in (select * from traw) loop
    select l1 into lobloc from tblob where n1=rec.n1 for update;
    buffer := rec.l1;
    amount := utl_raw.length(rec.l1);
    dbms_lob.write(lobloc,utl_raw.length(rec.l1),1,buffer);
    end loop;
    end;
    Example #2
    다음은 PL/SQL 를 이용해서 LONG columns 을 BLOBs 로 변환하는
    또 다른 방법입니다.
    REM long2lob.sql
    REM Version 1.0, last updated 8/8/97
    REM This procedure copies LONG data into a CLOB, as described in
    REM Chapter 21 of Oracle8 PL/SQL Programming by Scott Urman.
    CREATE OR REPLACE PROCEDURE Long2Lob(
    -- Uses DBMS_SQL to select a LONG column identified by p_LongQuery, and
    -- returns it in p_CLob.
    p_LongQuery IN VARCHAR2,
    p_CLob IN OUT CLOB) AS
    c_ChunkSize CONSTANT INTEGER := 100;
    v_CursorID INTEGER;
    v_RC INTEGER;
    v_Chunk VARCHAR2(100);
    v_ChunkLength INTEGER;
    v_Offset INTEGER := 0;
    BEGIN
    -- Open the cursor, define, execute, and fetch.
    v_CursorID := DBMS_SQL.OPEN_CURSOR;
    DBMS_SQL.PARSE(v_CursorID, p_LongQuery, DBMS_SQL.V7);
    DBMS_SQL.DEFINE_COLUMN_LONG(v_CursorID, 1);
    v_RC := DBMS_SQL.EXECUTE_AND_FETCH(v_CursorID);
    -- Loop over the LONG, fetching c_ChunkSize characters at a time from
    -- the LONG and adding them to the LOB.
    LOOP
    DBMS_SQL.COLUMN_VALUE_LONG(v_CursorID, 1, c_ChunkSize, v_Offset,
    v_Chunk, v_ChunkLength);
    DBMS_LOB.WRITE(p_CLob, v_ChunkLength, v_Offset + 1, v_Chunk);
    IF v_ChunkLength < c_ChunkSize THEN
    EXIT;
    ELSE
    v_Offset := v_Offset + v_ChunkLength;
    END IF;
    END LOOP;
    DBMS_SQL.CLOSE_CURSOR(v_CursorID);
    EXCEPTION
    WHEN OTHERS THEN
    -- Clean up, and reraise the error.
    DBMS_SQL.CLOSE_CURSOR(v_CursorID);
    RAISE;
    END Long2Lob;
    Reference Documents
    Note:1012454.7
    Note:168975.1

  • Jdbc session - LONG RAW or BLOB ?

    Hello,
              My over-large session data cannot use the LONG RAW data type, for session data field. I think that is a jdbc driver limitation.
              Session data does not appear to be saved at all if I use a 'BLOB' instead of LONG RAW. Does anyone know if this usually works ?
              The drivers I have tried are -
              oracle.jdbc.driver.OracleDriver
              weblogic.jdbc.oci.Driver
              Oracle 817
              Weblogic 6.1 sp 3
              thanks in advance,
              John
              

    Kiran,
    A long raw column can store up to 2 Go and you can have only one by table.
    With 9i, BLOB column can store up to 4Go and you can have as so many you want.
    With 10g, BLOB column can store up to 8To
    I suggest you to use BLOB columns.
    Francois

  • Limitation of converting from Long Raw to Blob

    Hi All,
    DB:11g
    Oracle Apps:R12
    Is there a limitation of converting from Long Raw to Blob?
    Please share your experience on this subject in case anyone has faced it before.
    Thanks for your time!
    Regards,

    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:13213885403654
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:510622111991

  • Insert from Long Raw to Blob

    Hi all,
    I'm presently working on oracle 8.1.7,im having a table with Long Raw as a field.
    I want to insert the image into another table which containing a Blob as field.I wanted it to take place either by Database trigger or Procedure or any other way..
    Please can anybody provide me the script. I've already tried the procedure..select long raw to blob..I'm getting Numeric or Value error...i think the size of the image in the long raw table might be > 32767...
    Urgent please...
    thanks in advance
    rgds,
    John

    Hi John,
    Post this question in Database forum for quick help.
    The forum is present at this location.
    General Database Discussions
    Regards,
    Anupama

Maybe you are looking for