Fetch LONG RAW Type?

Hello.
As, I said before, I am migrating OCI API from 7 to 8.
There are so many things that have been changed, so very hard to do it.
When I fetch the LONG RAW Type, How should I do?
in OCI7, I used oflng() API, but OCI8 OCILobRead() doens't work and there are no information in the OCI reference Guide.
I am getting worrying because of the schedule is delayed.
Thank you in advance.

Here is a LONG, LONG RAW would be almost identical.
This program inserts and then fetches a row from a table with a long column.
It is written in OCI8 using the standard piecewise operations, setting up the
pieces of data via OCIStmtSetPieceInfo and OCIStmtGetPieceInfo.
Program Notes
The program requires the following table to be created under the scott schema:
create table long_tab (c1 number, c2 long);
NOTE: To build the programs on unix use the demo makefile as follows:
make -f demo_rdbms.mk EXE=piece_ins_fetch OBJS=piece_ins_fetch.o build
make -f demo_rdbms.mk EXE=callback_ins_fetch OBJS=callback_ins_fetch.o build
References
Oracle Call Interface Programmer Guide, A76975-01
Caution
The sample program in this article is provided for educational purposes only
and is NOT supported by Oracle Support Services. It has been tested
internally, however, and works as documented. We do not guarantee that it
will work for you, so be sure to test it in your environment before relying
on it.
Programs
piece_ins_fetch.c:
- - - - - - - - - - - - - - - - Code begins here - - - - - - - - - - - - - - - -
* This example uses the following table:
* create table long_tab (c1 number, c2 long);
* It first inserts a row into the table using piecewise operations
* and then selects it out again the same way.
#include <stdio.h>
#include <string.h>
#include <oci.h>
* Prototypes.
static void checkerr(/*_ OCIError *errhp, sword status _*/);
#define CHUNK_SIZE 50
#define MAXLEN 200
* Error handling routine.
static void checkerr(errhp, status)
OCIError *errhp;
sword status;
text errbuf[512];
ub4 errcode;
switch (status)
case OCI_SUCCESS:
break;
case OCI_SUCCESS_WITH_INFO:
printf("Error - OCI_SUCCESS_WITH_INFO\n");
break;
case OCI_NEED_DATA:
printf("Error - OCI_NEED_DATA\n");
break;
case OCI_NO_DATA:
printf("Error - OCI_NO_DATA\n");
break;
case OCI_ERROR:
OCIErrorGet ((dvoid *)errhp,(ub4)1,(text *)NULL,(sb4 *)&errcode,
(text *)errbuf,(ub4)sizeof(errbuf),(ub4)OCI_HTYPE_ERROR);
printf("Error - %s\n", errbuf);
break;
case OCI_INVALID_HANDLE:
printf("Error - OCI_INVALID_HANDLE\n");
break;
case OCI_STILL_EXECUTING:
printf("Error - OCI_STILL_EXECUTING\n");
break;
case OCI_CONTINUE:
printf("Error - OCI_CONTINUE\n");
break;
default:
break;
* Main routine.
void main()
* Handles.
OCIEnv envhp;                    / Environment handle */
OCIError errhp;                    / Error handle */
OCIServer srvhp;                    / Server handle */
OCISvcCtx svchp;                    / Service context handle */
OCISession usrhp;                    / Session handle */
OCIStmt stmthp;                   / Statement handle */
* Other variables.
text selectStmt = (text)"select c2 from long_tab where c1 = 1";
text insertStmt = (text)"insert into long_tab values (1,:b1)";
OCIDefine *def1p = 0;
OCIBind *bnd1p = 0;
char buf[MAXLEN+1]; /* Buffer 1 */
char buf2[MAXLEN+1]; /* Buffer 2 */
char wherebuf;                      / Pointer to buf */
ub4 amount; /* Amount of data to read/write */
ub4 offset; /* Offset into buffer */
ub1 piece; /* Which piece */
ub4 total; /* Total size of buffer */
ub4 so_far; /* Amount inserted so far */
ub2 actual_len; /* Final length */
sword status;
ub4 type; /* For SetPieceInfo */
ub4 p_type; /* " " */
ub4 iteration; /* " " */
ub4 table; /* " " */
strcpy(buf,"This is some text to be inserted into a long column so we ");
strcat(buf,"can test using piecewise operations to read and write long data");
printf("Setting up environment and connecting...\n");
* Initialise the OCI environment.
OCIInitialize((ub4)OCI_OBJECT,(dvoid *)0,(dvoid * (*)())0,
(dvoid * (*)())0,(void (*)())0);
* Allocate and initialise the environment handle - no need to call
* call OCIHandleAlloc first.
OCIEnvInit((OCIEnv **)&envhp,(ub4)OCI_DEFAULT,(size_t)0,(dvoid **)0);
* Allocate the error handle for all error handling.
OCIHandleAlloc((dvoid *)envhp,(dvoid **)&errhp,(ub4)OCI_HTYPE_ERROR,
(size_t)0,(dvoid **)0);
* Allocate the server handle and create the access path by
* attaching. Note no connect string alias is being passed in the
* attach call as we are using a local connection.
OCIHandleAlloc((dvoid *)envhp,(dvoid **)&srvhp,(ub4)OCI_HTYPE_SERVER,
(size_t)0,(dvoid **)0);
checkerr(errhp,OCIServerAttach((OCIServer *)srvhp,(OCIError *)errhp,
(text *)0,(sb4)0,(ub4)OCI_DEFAULT));
* Allocate the service context handle and set the server attribute to
* the server handle allocated above.
OCIHandleAlloc((dvoid *)envhp,(dvoid **)&svchp,(ub4)OCI_HTYPE_SVCCTX,
(size_t)0,(dvoid **)0);
OCIAttrSet((dvoid *)svchp,(ub4)OCI_HTYPE_SVCCTX,
(dvoid *)srvhp,(ub4)0,
(ub4)OCI_ATTR_SERVER,(OCIError *)errhp);
* Allocate the session handle, set the username and password properties
* and connect. Add the session handle to the session attribute of the
* service context.
OCIHandleAlloc((dvoid *)envhp,(dvoid **)&usrhp,(ub4)OCI_HTYPE_SESSION,
(size_t)0,(dvoid **)0);
OCIAttrSet((dvoid *)usrhp,(ub4)OCI_HTYPE_SESSION,
(dvoid *)"scott",(ub4)strlen("scott"),
(ub4)OCI_ATTR_USERNAME,(OCIError *)errhp);
OCIAttrSet((dvoid *)usrhp,(ub4)OCI_HTYPE_SESSION,
(dvoid *)"tiger",(ub4)strlen("tiger"),
(ub4)OCI_ATTR_PASSWORD,(OCIError *)errhp);
checkerr(errhp,OCISessionBegin((OCISvcCtx *)svchp,(OCIError *)errhp,
(OCISession *)usrhp,
OCI_CRED_RDBMS,OCI_DEFAULT));
OCIAttrSet((dvoid *)svchp,(ub4)OCI_HTYPE_SVCCTX,
(dvoid *)usrhp,(ub4)0,
(ub4)OCI_ATTR_SESSION,(OCIError *)errhp);
printf("Set up done. Connected.\n");
* Logged on and ready to go.
* Set up the insert.
OCIHandleAlloc((dvoid *)envhp,(dvoid **)&stmthp,
(ub4)OCI_HTYPE_STMT,(size_t)0,(dvoid **)0);
checkerr(errhp,OCIStmtPrepare((OCIStmt *)stmthp,(OCIError *)errhp,
(CONST text*)insertStmt,
(ub4)strlen((char*)insertStmt),
(ub4)OCI_NTV_SYNTAX,(ub4)OCI_DEFAULT));
checkerr(errhp,OCIBindByName((OCIStmt *)stmthp,(OCIBind **)&bnd1p,
(OCIError *)errhp,(CONST text*)":b1",
(sb4)-1,(dvoid *)0,(sb4)MAXLEN,
(ub2)SQLT_LNG,(dvoid *)0,(ub2 *)0,
(ub2 *)0,(ub4)0,(ub4 *)0,(ub4)OCI_DATA_AT_EXEC));
printf("Inserting data...\n");
status = OCIStmtExecute((OCISvcCtx *)svchp,(OCIStmt *)stmthp,
(OCIError *)errhp,(ub4)1,
(ub4)0,(CONST OCISnapshot *)NULL,
(OCISnapshot *)NULL,(ub4)OCI_DEFAULT);
if (status != 0 && status != OCI_NEED_DATA)
checkerr(errhp,status);
offset = 1;
total = strlen(buf);
so_far = 0;
if (total <= CHUNK_SIZE)
amount = total;
piece = OCI_ONE_PIECE;
else
amount = CHUNK_SIZE;
piece = OCI_FIRST_PIECE;
while (so_far < total)
wherebuf = &buf[offset-1];
checkerr(errhp,OCIStmtSetPieceInfo((dvoid *)bnd1p,
(ub4)OCI_HTYPE_BIND,
(OCIError *)errhp,
(CONST dvoid *)wherebuf,
(ub4 *)&amount,
(ub1)piece,
(CONST dvoid *)0, /* no indicator */
(ub2 *)0));
status = OCIStmtExecute((OCISvcCtx *)svchp,(OCIStmt *)stmthp,
(OCIError *)errhp,(ub4)1,
(ub4)0,(CONST OCISnapshot *)NULL,
(OCISnapshot *)NULL,(ub4)OCI_DEFAULT);
if (status != 0 && status != OCI_NEED_DATA)
checkerr(errhp,status);
break;
if (amount < CHUNK_SIZE)
so_far += amount;
else if (amount == total)
so_far = total;
else
so_far += CHUNK_SIZE;
printf("Written %ld bytes\n",so_far);
if (total <= so_far+CHUNK_SIZE)
/* We'll be done next go */
piece = OCI_LAST_PIECE;
amount = total - so_far;
else
piece = OCI_NEXT_PIECE;
offset += CHUNK_SIZE;
printf("Wrote %d bytes of data\n",total);
printf("Commiting ...\n");
checkerr(errhp,OCITransCommit((OCISvcCtx *)svchp,
(OCIError *)errhp,(ub4)0));
* Set up the select.
checkerr(errhp,OCIStmtPrepare((OCIStmt *)stmthp,(OCIError *)errhp,
(CONST text*)selectStmt,
(ub4)strlen((char*)selectStmt),
(ub4)OCI_NTV_SYNTAX,(ub4)OCI_DEFAULT));
actual_len = 0;
checkerr(errhp,OCIDefineByPos((OCIStmt *)stmthp,(OCIDefine **)&def1p,
(OCIError *)errhp,(ub4)1,(dvoid *)0,
(sb4)MAXLEN,(ub2)SQLT_LNG,
(dvoid *)0,(ub2 *)&actual_len,
(ub2 *)0,(ub4)OCI_DYNAMIC_FETCH));
printf("\nSelecting data...\n");
checkerr(errhp,OCIStmtExecute((OCISvcCtx *)svchp,(OCIStmt *)stmthp,
(OCIError *)errhp,(ub4)0,
(ub4)0,(CONST OCISnapshot *)NULL,
(OCISnapshot *)NULL,(ub4)OCI_DEFAULT));
status = OCIStmtFetch((OCIStmt *)stmthp,(OCIError *)errhp,(ub4)1,
(ub2)OCI_FETCH_NEXT,(ub4)OCI_DEFAULT);
if (status != 0 && status != OCI_NEED_DATA)
checkerr(errhp,status);
amount = CHUNK_SIZE;
offset = 1;
while (status == OCI_NEED_DATA)
wherebuf = &buf2[offset-1];
checkerr(errhp,OCIStmtGetPieceInfo((OCIStmt *)stmthp,
(OCIError *)errhp,
(dvoid **)&def1p,
(ub4 *)&type,
(ub1 *)&p_type,
(ub4 *)&iteration,
(ub4 *)&table,
(ub1 *)&piece));
checkerr(errhp,OCIStmtSetPieceInfo((dvoid *)def1p,
(ub4)OCI_HTYPE_DEFINE,
(OCIError *)errhp,
(CONST dvoid *)wherebuf,
(ub4 *)&amount,
(ub1)piece,
(CONST dvoid *)0, /* no indicator */
(ub2 *)0));
status = OCIStmtFetch((OCIStmt *)stmthp,(OCIError *)errhp,(ub4)1,
(ub2)OCI_FETCH_NEXT,(ub4)OCI_DEFAULT);
if (status != 0 && status != OCI_NEED_DATA)
checkerr(errhp,status);
break;
printf("Fetched %d characters: %.*s\n",amount,amount,wherebuf);
offset += amount;
printf("\nTotal amount of data read is %d characters\n",actual_len);
buf2[actual_len] = '\0';
printf("Retrieved data is:\n%s\n",buf2);
* Time to clear up and exit:
* Free the statement handle - this will auto free any bind and
* define pointers
* End the session
* Detach the server
* Free the server, service context, session, error and environment
* handles
OCIHandleFree((dvoid *)stmthp,(ub4)OCI_HTYPE_STMT);
checkerr(errhp,OCISessionEnd((OCISvcCtx *)svchp,(OCIError *)errhp,
(OCISession *)usrhp,(ub4)OCI_DEFAULT));
checkerr(errhp,OCIServerDetach((OCIServer *)srvhp,(OCIError *)errhp,
(ub4)OCI_DEFAULT));
OCIHandleFree((dvoid *)srvhp,(ub4)OCI_HTYPE_SERVER);
OCIHandleFree((dvoid *)svchp,(ub4)OCI_HTYPE_SVCCTX);
OCIHandleFree((dvoid *)usrhp,(ub4)OCI_HTYPE_SESSION);
OCIHandleFree((dvoid *)errhp,(ub4)OCI_HTYPE_ERROR);
OCIHandleFree((dvoid *)envhp,(ub4)OCI_HTYPE_ENV);
- - - - - - - - - - - - - - - - Code ends here - - - - - - - - - - - - - - - -
Sample Output
Setting up environment and connecting...
Set up done. Connected.
Inserting data...
Written 50 bytes
Written 100 bytes
Written 121 bytes
Wrote 121 bytes
Commiting ...
Selecting data...
Fetched 50 characters: This is some text to be inserted into a long colum
Fetched 50 characters: n so we can test using piecewise operations to rea
Fetched 21 characters: d and write long data
Total amount of data read is 121 characters
Retrieved data is:
This is some text to be inserted into a long column so we can test using
piecewise operations to read and write long data

Similar Messages

  • How tu update a column having type 'Long raw' in oracle table with an image

    Hello,
    I must change the image loading in a column with 'long raw' type in the table. I find an image data already in the table.
    I have my new imgae in a file .bmp.
    What SQL instruction I mut use to update this column to load my new image ?
    I work in Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod.
    thanks for your helps.
    Regards.

    Unless I'm missing something MSFT are making it unecessarily complex by not implementing the SQL/XML standard...
    SQL> alter table emp add ( emp_xml xmltype)
      2  /
    Table altered.
    SQL> update emp set emp_xml = XMLELEMENT("EMPLOYEE",xmlattributes(EMPNO as "id"), XMLElement("Name",ENAME))
      2
    SQL> /
    14 rows updated.
    SQL> set pages 0
    SQL> select EMPNO, EMP_XML from EMP
      2  /
          7369
    <EMPLOYEE id="7369">
      <Name>SMITH</Name>
    </EMPLOYEE>
          7499
    <EMPLOYEE id="7499">
      <Name>ALLEN</Name>
    </EMPLOYEE>
          7521
    <EMPLOYEE id="7521">
      <Name>WARD</Name>
    </EMPLOYEE>
          7566
    <EMPLOYEE id="7566">
      <Name>JONES</Name>
    </EMPLOYEE>
          7654
    <EMPLOYEE id="7654">
      <Name>MARTIN</Name>
    </EMPLOYEE>
          7698
    <EMPLOYEE id="7698">
      <Name>BLAKE</Name>
    </EMPLOYEE>
          7782
    <EMPLOYEE id="7782">
      <Name>CLARK</Name>
    </EMPLOYEE>
          7788
    <EMPLOYEE id="7788">
      <Name>SCOTT</Name>
    </EMPLOYEE>
          7839
    <EMPLOYEE id="7839">
      <Name>KING</Name>
    </EMPLOYEE>
          7844
    <EMPLOYEE id="7844">
      <Name>TURNER</Name>
    </EMPLOYEE>
          7876
    <EMPLOYEE id="7876">
      <Name>ADAMS</Name>
    </EMPLOYEE>
          7900
    <EMPLOYEE id="7900">
      <Name>JAMES</Name>
    </EMPLOYEE>
          7902
    <EMPLOYEE id="7902">
      <Name>FORD</Name>
    </EMPLOYEE>
          7934
    <EMPLOYEE id="7934">
      <Name>MILLER</Name>
    </EMPLOYEE>
    14 rows selected.
    SQL>

  • ORA-06502 trying to load a long raw into a variable.

    Hi. In my table "banco_imagem" the bim_src column is a long raw type.
    I´m using oracle forms 6 (not 6i), so I can´t use blob type to save my images.
    Now I´m trying to load the long raw column into a variable in a package that runs on 10g.
    I´m trying to execute de folowing code at sql plus:
    declare
    wbim   long raw;
    begin
    select bim_src into wbim from banco_imagem where rownum=1;
    end;
    The column is not null. It has a value.
    I got the folowing error:
    ORA-06502: PL/SQL: numeric or value error
    ORA-06512: at line 4
    My goal is to load this column to convert it to blob so I can manipulate with my others (already running) functions.
    Can anyone help me?
    Thanks!

    Hi Mcardia,
    not sure where you're going wrong, but perhaps if you compare what you've done up to now to the following code snippet, you may figure it out eventually!
    SQL> drop table test_raw
      2  /
    Table dropped.
    SQL>
    SQL> create table test_raw (col_a long raw, col_b blob)
      2  /
    Table created.
    SQL> set serveroutput on
    SQL> declare
      2 
      3    l1 long raw;
      4    l2 long raw;
      5   
      6    b1 blob;
      7   
      8  begin
      9 
    10    l1:= utl_raw.cast_to_raw('This is a test');
    11   
    12    insert into test_raw (col_a) values (l1);
    13 
    14       
    15    select col_a
    16    into   l2
    17    from    test_raw
    18    where   rownum < 2;
    19   
    20    dbms_lob.createtemporary (b1, false);
    21   
    22    dbms_output.put_line(utl_raw.cast_to_varchar2(l2));
    23    b1 := l2;
    24 
    25    update  test_raw set col_b = b1;
    26   
    27    commit;
    28   
    29    dbms_output.put_line('Done ');
    30   
    31    exception
    32      when others then
    33        dbms_output.put_line('Error ' || sqlerrm);
    34  end;
    35  /
    This is a test
    Done
    PL/SQL procedure successfully completed.Bear in mind that I'm running on the following:
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    PL/SQL Release 10.2.0.4.0 - Production
    CORE 10.2.0.4.0 Production
    TNS for Solaris: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - Production

  • 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

  • Select Long Raw data type is so slow?

    Hi
    I have a table having Long Raw data type field.It's store
    more than 2mb per record.But,I need to select others fields in this table without selecting Long Raw field.
    anyway,it's so slow for me. Any advise to me?
    thx a lot. :)

    I do not understand what you mean because if you have this table ( Example ):
    c1 number
    c2 number
    c3 long
    you can do this: select c1, c2 from <table_name>;
    Joel Pérez

  • Long, Raw, Lob Data types in OWB.

    Hi All,
    Is it posssible to load data of the type LONG, RAW, LOB etc from a source text file or oracle source table to a target text file or oracle target table.?
    I believe this option is not available in OWB 9.0.2.56 version.
    Thanks in Advance.
    Regards,
    Vidyanand

    Good morning Rita,
    These datatypes should be supported by 'Paris'.
    When saying "nor can I view the data in the source", is that using a SQL-client (SQL*Plus, TOAD, whatever)?
    I'm also on the beta program but haven't been able to do anything yet (hopefully tomorrow), but what I remember reading is that in case of problems you could directly email a member of the OWB-development team (Nikolai Rochnik I think it was). If that thought is correct, you might want to address him (or any other person in that team).
    Good luck, Patrick

  • Inserting into long raw column type

    Hello,
    We tried to insert into a bmp file into the a column of type long raw and got the following error: "invalid value stored in pcbValue". There was no ORA message code assign to this error.
    Willy

    Thanks !
    JDeveloper Team (guest) wrote:
    : Hi,
    : You need to use streams to do this. In the JDBC User's Guide
    and
    : Reference, there is a whole chapter on using streams. Here is
    : some example code from the 8.1.5 JDBC User's Guide:
    : The following Java code snippet writes the data from the
    LESLIE
    : LONG RAW column into a file called
    : leslie.gif:
    : ResultSet rset = stmt.executeQuery ("select GIFDATA from
    : streamexample where
    : NAME='LESLIE'");
    : // get first row
    : if (rset.next())
    : // Get the GIF data as a stream from Oracle to the client
    : InputStream gif_data = rset.getBinaryStream (1);
    : try
    : FileOutputStream file = null;
    : file = new FileOutputStream ("leslie.gif");
    : int chunk;
    : while ((chunk = gif_data.read()) != -1)
    : file.write(chunk);
    : } catch (Exception e) {
    : String err = e.toString();
    : System.out.println(err);
    : } finally {
    : if file != null()
    : file.close();
    : In this example the contents of the GIFDATA column are
    : transferred incrementally in chunk-sized pieces between
    : the database and the client. The InputStream object returned
    by
    : the call to getBinaryStream() reads the data
    : directly from the database connection.
    : Zvonimir Vukovi (guest) wrote:
    : : Zvonimir Vukovic (guest) wrote:
    : : : Hi !
    : : : I have a problem when inserting an image (eg. GIF file)
    : into
    : : : Long Raw column. I am using JDeveloper 1.1, and I need to
    : read
    : : : images from my local hard drive and insert them into
    Oracle
    : : : DBMS. I've done a reverse thing (copying image from Long
    Raw
    : : : column to my HDD). I would be very thankful for a piece of
    : : JDBC
    : : : code which would solve my problem.
    : : : Thanks,
    : : : Zvonimir Vukovi
    : : I've forgotten to say that I need to use na Applet to do
    the
    : : job. I can read the image into AWT Image control, but I
    don't
    : : know how to get it into the Long Raw column
    : : Thanks again.
    : : Z.V.
    null

  • Xmlgen.getxml Nested Cursors with LONG RAW and BLOB Data Types

    I am trying to use a nested cursor with xmlgen.getxml that has a long raw or blob column. In either case, it will not return to me any data in the xml document pertaining to that LONG RAW or BLOB column. If I do not use a nested cursor, it works fine.
    Example:
    SELECT xmlgen.getxml('SELECT x, CURSOR(SELECT y FROM y_tab WHERE y_tab.x_id = x_tab.x_id) y FROM x_tab') FROM dual;
    This will not produce the information I am after.
    However, simply running:
    SELECT xmlgen.getxml('SELECT y FROM y_tab WHERE y_tab.x_id = <somevalue>') FROM dual;
    Works???
    Any ideas out there? Does anyone know if DBMS_XMLQUERY has this limitation?
    Thanks,
    Brad

    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

  • How to read LONG RAW data from one  table and insert into another table

    Hello EVERYBODY
    I have a table called sound with the following attributes. in the music attribute i have stored some messages in the different language like hindi, english etc. i want to concatinate all hindi messages and store in the another table with only one attribute of type LONG RAW.and this attribute is attached with the sound item.
    when i click the play button of sound item the all the messages recorded in hindi will play one by one automatically. for that i'm doing the following.
    i have written the following when button pressed trigger which will concatinate all the messages of any selected language from the sound table, and store in another table called temp.
    and then sound will be played from the temp table.
    declare
         tmp sound.music%type;
         temp1 sound.music%type;
         item_id ITEM;
    cursor c1
    is select music
    from sound
    where lang=:LIST10;
    begin
         open c1;
         loop
              fetch c1 into tmp; //THIS LINE GENERATES THE ERROR
              temp1:=temp1||tmp;
              exit when c1%notfound;
         end loop;
    CLOSE C1;
    insert into temp values(temp1);
    item_id:=Find_Item('Music');
    go_item('music');
    play_sound(item_id);
    end;
    but when i'm clicking the button it generates the following error.
    WHEN-BUTTON-PRESSED TRIGGER RAISED UNHANDLED EXCEPTION ORA-06502.
    ORA-06502: PL/SQL: numeric or value error
    SQL> desc sound;
    Name Null? Type
    SL_NO NUMBER(2)
    MUSIC LONG RAW
    LANG CHAR(10)
    IF MY PROCESS TO SOLVE THE ABOVE PROBLEM IS OK THEN PLESE TELL ME THE SOLUTION FOR THE ERROR. OTHER WISE PLEASE SUGGEST ME,IF ANY OTHER WAY IS THERE TO SOLVE THE ABOVE PROBLEM.
    THANKS IN ADVANCE.
    D. Prasad

    You can achieve this in many different ways, one is
    1. Create another VO based on the EO which is based on the dest table.
    2. At save, copy the contents of the source VO into the dest VO (see copy routine in dev guide).
    3. commiting the transaction will push the data into the dest table on which the dest VO is based.
    I understand that if we attach VO object instance to region/page, we only can pull and put data in to only one table.
    if by table you mean a DB table, then no, you can have a VO based on multiple EOs which will do DMLs accordingly.Thanks
    Tapash

  • Moving Long Raw from one table to another

    How to copy the record stored in a table which has Long Raw column and insert into another table
    The follwoing code is giving a numeric or value error
    declare
    BLOB_ID NUMBER(12);
    BLOB_FILE LONG RAW;
    Cursor c1 is select
    BLOB_ID ,
    BLOB_FILE from test ;
    Begin
         Open c1;
         Loop
         Fetch c1 into
         blob_id,
         blob_file;
         Exit when c1%notfound;
         End loop;
         Close c1;
    End;

    I don't see any problem with your code. Are you sure that the type of your variables matches the datatypes of blob_id and blob_file?
    sql>create table test (blob_id number(12), blob_file long raw);
    Table created.
    sql>create table test_copy (blob_id number(12), blob_file long raw);
    Table created.
    sql>insert into test values (1, utl_raw.cast_to_raw(lpad('x', 40, 'x')));
    1 row created.
    sql>declare
      2    blob_id    test.blob_id%type;
      3    blob_file  test.blob_file%type;
      4    cursor c1 is
      5      select blob_id, blob_file from test;
      6  begin
      7    open c1;
      8    loop
      9      fetch c1 into blob_id, blob_file;
    10      exit when c1%notfound;
    11      insert into test_copy values (blob_id, blob_file);
    12    end loop;
    13    close c1;
    14    commit;
    15  end;
    16  /
    PL/SQL procedure successfully completed.
    sql>select * from test_copy;
      BLOB_ID B
            1 7

  • How to differentiate picture formats in LONG RAW column?

    Hi,
    I have a table with a long raw column that contains pictures. I would like to know for each row if the picture in the long raw column is in JPEG, TIFF, BMP, etc.
    Does somebody have an idea on how to do this?
    Thanks!
    Matt

    1) You really shouldn't be using LONG or LONG RAW data types any longer. You should at least be using BLOB data types here.
    2) When you designed the schema, there should have been columns (or other tables) to store metadata about the file, including the type of image a row stores.
    3) Lacking any of this, you could write a program that fetches the data and determines whether it is a valid JPEG, then checks to see if it is a valid TIFF, etc. until it happens upon a file format that appears to work. Obviously, though, that is a relatively costly exercise. If that's what you're forced to do, I'd strongly encourage you to store that information in a (potentially new) column in the database so you only have to do it once.
    Justin

  • Problems with LONG RAW column

    We have a LONG RAW column.
    JDev mapped it to Raw and LONGVARBINARY as SQL type.
    Reading data (even huge amounts) works alright, but when we try to insert or update we get:
    Data size bigger than max size for this type
    I did some reading on the internet and found that I had to stream data into JDBC which Raw apparently cannot handle.
    So how can I solve this?
    And please, don't just write "Create a domain". I tried. It's not that easy for me. It should be a bit more specific.
    Thanks in advance!
    Sascha

    You not only have to create a Domain but also implement either BlobDomainInterface or one of it's subclassed interfaces.
    See oracle.jbo.domain.BlobDomainInterface (source in bc4jdomorcl-src.zip) for an example of how various interface methods are implemented.
    When a domain implements BlobDomainInterface, it's called during load/save Entity data to setup it's transaction context (if it needs to during load) and to save it's content into the db using the given transaction context.
    These interfaces are written with the assumption that there's an oracle.sql.* class that knows how to use transaction to fetch data using SQL-locator objects. In this case I believe you will need to extend the domain from oracle.sql.RAW class.

  • Reading and Inserting Value in Long Raw

    Hi guys !!
    I have a table with 15 columns out of which RESUME column has data type long Raw. I want to copy this table to another table with selectd columns and validation. I want to check whether RESUME column is NULL. How to achieve it ?
    Similarly, using VB how to insert and retrieve values in such column ?
    thanx in advance
    Abhi

    do one thing ,
    Create a summary item for detail amount column, say m_tot_amt
    Set its fol. properties
    Calculation Mode : Summary
    Summary : Sum
    Summ.Blk : Your detail blk
    Summ. Item : Your detail amount item
    Also, Set Query all records of your detail block as Yes
    Then In PRE-INSERT/ PRE_UPDATE of detail block, write
    :COP_ORDER_HEADER.DISCOUNT_AMOUNT := nvl(:m_tot_amt,0) ;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How to deal with LONG data type in RTF template

    Hi,
    I'm developing a PO request report in which I should print some attachments. The attachments are stored in the database in table fnd_attachments_long_text in column long_text which data type is LONG. In my case the content of the column long_text is always plain text.
    The query I use to get the text from the table is something like:
    select long_text
    from fnd_documents_long_text
    where <some_conditions....>
    The query runs fine in SQL developer but when I run the XML report I get following error: "Stream has already been closed". The XML file generated is complete in its structure but the XML node which should contain the text of the attachment is empty, therefore I cannot print the attachment in the report.
    I made some researches on metalink and I've found note 832903.1 which explains the same error I'm getting. Looks like I cannot execute more than 1 query using the same JDBC connection if one of these queries retrieves a LONG data type.
    Any advice on how can I get the attachment text to show correctly in my report?
    Thank you

    Hi,
    Thank you for your reply,
    Yes, I tried to get the text as described in that article but maybe I'm missing something because my data template doesn't show the attachment text.
    The article talks about support for BLOB, CLOB and RAW and at the end it states "but we do not have support for RAW and LONG column types at the moment - we're looking into that for a future release". So this makes me think that I won't be albe to retrieve my text since it's stored in a LONG column.
    I think that the error I'm getting is not strictly related to XML publisher but it is in some way related to the JDBC connection used to get the data. Infact I have an old version of the same report I'm trying do develop which is made in Report Builder and it is retrieving the attachment text correctly.
    Right now I'm trying to use the Report Builder engine to get the XML data and then use XML Publisher to create the PDF output. Anyway, if it is possible, I would like to avoid Report Builder and use only XMLP.
    Thanks

  • 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

Maybe you are looking for