Writing BLOB column into a file (NT/WinWord)

I need to create
a file on NT and extract the contents of a BLOB
column and put it in the file. It's a WORD-document
and I'm using 8.1.7 on NT4SP5. I'm thinking some
combination of the LOB package and UTL_FILE, but
some far no luck. Example code would help me.
Thanks in advance
Dannys

dbms_lob, utl_lob is not supported by oracle, written by an in-
house analyst to demonstrate a concept.

Similar Messages

  • Writing BLOB column into a csv or txt or sql  files

    Hi All,
    I am having a requirement where i have to upload a file from user desktop and place that file into a unix directory. For this i am picking that file into a table using APEX and then writing that file in unix directory using UTL_FILE.
    The problem which i am facing is that after this every line in my file is having ^M character at the end.
    For this i modified my BLOB column into a CLOB column and then also i am facing the same problem.
    Is there any way to get rid of this as i have to upload these csv or txt files into tables using sql loader programs. i can;t write any shell script to remove ^M character before uploading as this program will be merge with existing programs and then it will require lots of code change.
    Kindly Help.
    Thanks
    Aryan

    Hi Helios,
    Thanks again buddy for your reply and providing me different ways.... but still the situation is i can;t write any shell script for removing the ^M. I will be writing into a file from CLOB column.
    Actually the scenrio is when i am writing a simple VARCHAR columns with 'W' mode then it is working fine, but i have a BLOB column which stores the data in binary format so i am converting that column into CLOB and then writing it into file with 'W' mode but then i am getting ^M characters. As per your suggestion i have to then again run a program for removing ^M or i have to modify all my previous programs for removing ^M logic.
    I want to avoid all these, and just wanted a way so that while writing into a file itself it should not have ^M. Else i have to go for a java stored procedure for running a shell script from sql, and in this still i am having some problem.
    Thanks Again Helios for your time and help.
    Regards
    Aryan

  • Write blob value into a file

    Hi, all
    I'm looking for the correct method of writing an internal blob value into a file. I know that the best way is using some external language. I.e. Java or C. But also I met a number of solutions of doing within pl/SQL block. All of them look like this:
    CREATE OR REPLACE PROCEDURE Write_Binary_file
       PC$Directory IN VARCHAR2
      ,PC$File_Name IN VARCHAR2
      ,PC$SQL_Order IN VARCHAR2
      ,PB$Raise     IN BOOLEAN DEFAULT FALSE
    -- Procedure to dump a BLOB column onto a file
    -- parameters:
    -- PC$Directory : name of an existing Oracle Directory
    -- PC$File_Name : name of the expected output file
    -- PC$SQL_Order : SQL order to select the BLOB column
    -- PB$Raise     : boolean to indicate if the process
    --                would be stopped after an error
    IS
      src_lob    BLOB;
      buffer     RAW(16384);
      amt        BINARY_INTEGER := 16384;
      pos        INTEGER := 1;
      LF$FicOUT  UTL_FILE.FILE_TYPE ;
      LC$Msg     VARCHAR2(2000) ;
    BEGIN
    -- get the BLOB column --
    BEGIN
      EXECUTE IMMEDIATE PC$SQL_Order INTO src_lob ;
    EXCEPTION
      WHEN NO_DATA_FOUND THEN
        LC$Msg := 'Write_Binary_File(): NO_DATA_FOUND' ;
        IF PB$Raise THEN
          RAISE_APPLICATION_ERROR( -20100, LC$Msg ) ;
        END IF ;
        Dbms_Output.Put_Line(LC$Msg) ;
      RETURN ;
    END ;
    -- open the output file --
    LF$FicOUT := UTL_FILE.FOPEN( PC$Directory, PC$File_Name, 'W', 32764 ) ;
    -- write the file --
    LOOP
      -- read the chunks --
      Dbms_Lob.READ (src_lob, amt, pos, buffer);
      -- write the chunks --
      Utl_File.Put_Raw(LF$FicOut, buffer);
      pos := pos + amt;
    END LOOP;
    -- close the file --
    Utl_File.Fclose(LF$FicOut);
    EXCEPTION
      WHEN NO_DATA_FOUND THEN
        utl_file.fclose(LF$FicOut);
      WHEN OTHERS THEN
        LC$Msg := 'Write_Binary_File() Error : ' || TO_CHAR( SQLCODE ) || ' while managing file ('
    || PC$Directory || ') ' || PC$File_Name ;
        IF PB$Raise THEN
          RAISE_APPLICATION_ERROR( -20100, LC$Msg ) ;
        END IF ;
        Dbms_Output.Put_Line(LC$Msg);
    END Write_Binary_file;
    But this code seems not working. The problem is it always creates a file with a bit bigger size than initial one. So jpg copy will be never be opened with any viewer.
    Can anybody explain this issue and give any workaround?
    Thanks

    You need a code block like this:
    DECLARE
       l_file       UTL_FILE.FILE_TYPE;
       l_buffer     RAW (32767);
       l_amount     BINARY_INTEGER     := 32767;
       l_pos        INTEGER            := 1;
       l_blob       BLOB;
       l_blob_len   INTEGER;
    BEGIN
    -- Open the destination file. Note the third parameter "wb"
       l_file := UTL_FILE.FOPEN ('TEST_DIR', 'extract3.jpg', 'wb');
    -- Get LOB locator
    FOR rec IN (
    SELECT blob_col  l_blob
          FROM test_my_blob
       --AND ROWNUM =1
    LOOP
       l_blob_len := DBMS_LOB.getlength (rec.l_blob);
    -- Read chunks of the BLOB and write them to the file
    -- until complete.
       WHILE l_pos < l_blob_len
       LOOP
          DBMS_LOB.READ (rec.l_blob, l_amount, l_pos, l_buffer);
          UTL_FILE.put_raw (l_file, l_buffer, FALSE);
          l_pos := l_pos + l_amount;
       END LOOP;
      commit;
    END LOOP;
    -- Close the file.
       UTL_FILE.FCLOSE (l_file);
    EXCEPTION
       WHEN OTHERS
       THEN
    -- Close the file if something goes wrong.
          IF UTL_FILE.IS_OPEN (l_file)
          THEN
             UTL_FILE.FCLOSE (l_file);
          END IF;
          RAISE;
    END;

  • Writing blob value to a file

    I am using the below code to write the contents of a blob column in a table to a txt file. My procedure is getting executed successfully.But I am not able to find the text file in the given directory.
    SQL> CREATE OR REPLACE PROCEDURE Write_Binary_file
    2 (
    3 pcdir IN VARCHAR2
    4 ,pcflnm IN VARCHAR2
    5 ,P_raise IN BOOLEAN DEFAULT FALSE
    6 )
    7 -- -------------------------------------------
    8 -- Procedure to dump a BLOB column onto a file
    9 -- -------------------------------------------
    10 -- parameters:
    11 -- pcdir : name of an existing Oracle Directory
    12 -- pcflnm : name of the expected output file
    13 -- P_raise : boolean to indicate if the process
    14 -- would be stopped after an error
    15 --
    16 IS
    17 src_lob BLOB;
    18 buffer RAW(16384);
    19 amt BINARY_INTEGER := 16384;
    20 pos INTEGER := 1;
    21 out_file UTL_FILE.FILE_TYPE ;
    22 Err_msg VARCHAR2(2000) ;
    23 BEGIN
    24
    25 -- get the BLOB column --
    26 BEGIN
    27 select CONTENT_DATA INTO src_lob from pstars.REPORT_INSTANCES where id=29;
    28 EXCEPTION
    29 WHEN NO_DATA_FOUND THEN
    30 Err_msg := 'Write_Binary_File(): NO_DATA_FOUND' ;
    31 IF P_raise THEN
    32 RAISE_APPLICATION_ERROR( -20100, Err_msg ) ;
    33 END IF ;
    34 Dbms_Output.Put_Line(Err_msg) ;
    35 RETURN ;
    36 END ;
    37
    38 -- open the output file --
    39 out_file := UTL_FILE.FOPEN( pcdir, pcflnm, 'W', 32764 ) ;
    40
    41 -- write the file --
    42 while pos<dbms_lob.getlength(src_lob)
    43 LOOP
    44 -- read the chunks --
    45 Dbms_Lob.READ (src_lob, amt, pos, buffer);
    46 -- write the chunks --
    47 Utl_File.Put_Raw(out_file, buffer);
    48 pos := pos + amt;
    49 END LOOP;
    50 -- close the file --
    51 Utl_File.Fclose(out_file);
    52
    53 EXCEPTION
    54 WHEN NO_DATA_FOUND THEN
    55 utl_file.fclose(out_file);
    56 WHEN OTHERS THEN
    57 Err_msg := 'Write_Binary_File() Error : ' || TO_CHAR( SQLCODE ) || ' while managing file ('
    58 || pcdir || ') ' || pcflnm ;
    59 IF P_raise THEN
    60 RAISE_APPLICATION_ERROR( -20100, Err_msg ) ;
    61 END IF ;
    62 Dbms_Output.Put_Line(Err_msg);
    63 END Write_Binary_file;
    64 /
    Procedure created
    SQL> exec Write_Binary_file('dir_temp','rpt_inst.txt');
    PL/SQL procedure successfully completed
    SQL> select * from dba_directories;
    OWNER DIRECTORY_NAME DIRECTORY_PATH
    SYS VWC D:\Oracle9iserver\vwcode
    SYS MYDIR C:\load_SLD\
    SYS DIR_TEMP D:\temp
    SQL> exec Write_Binary_file('VWC','rpt_inst.txt');
    PL/SQL procedure successfully completed
    SQL>

    Your exception code is wrong because if P_RAISE is set to FALSE you won't see any exception.
    Run you code with P_RAISE set to TRUE and with:
    set serveroutput on

  • Error while writing the data into the file . can u please help in this.

    The following error i am getting while writing the data into the file.
    <bindingFault xmlns="http://schemas.oracle.com/bpel/extension">
    <part name="code">
    <code>null</code>
    </part>
    <part name="summary">
    <summary>file:/C:/oracle/OraBPELPM_1/integration/orabpel/domains/default/tmp/
    .bpel_MainDispatchProcess_1.0.jar/IntermediateOutputFile.wsdl
    [ Write_ptt::Write(Root-Element) ] - WSIF JCA Execute of operation
    'Write' failed due to: Error in opening
    file for writing. Cannot open file:
    C:\oracle\OraBPELPM_1\integration\jdev\jdev\mywork\
    BPEL_Import_with_Dynamic_Transformation\WORKDIRS\SampleImportProcess1\input for writing. ;
    nested exception is: ORABPEL-11058 Error in opening file for writing.
    Cannot open file: C:\oracle\OraBPELPM_1\integration\jdev\jdev\mywork\
    BPEL_Import_with_Dynamic_Transformation
    \WORKDIRS\SampleImportProcess1\input for writing. Please ensure 1.
    Specified output Dir has write permission 2.
    Output filename has not exceeded the max chararters allowed by the
    OS and 3. Local File System has enough space
    .</summary>
    </part>
    <part name="detail">
    <detail>null</detail>
    </part>
    </bindingFault>

    Hi there,
    Have you verified the suggestions in the error message?
    Cannot open file: C:\oracle\OraBPELPM_1\integration\jdev\jdev\mywork\BPEL_Import_with_Dynamic_Transformation\WORKDIRS\SampleImportProcess1\input for writing.
    Please ensure
    1. Specified output Dir has write permission
    2. Output filename has not exceeded the max chararters allowed by the OS and
    3. Local File System has enough space
    I am also curious why you are writing to a directory with the name "..\SampleImportProcess1\input" ?

  • Writing BLOB column from Cobol

    Hi,
    I´m using the Pro*Cobol pre-compile to execute SQL statements into programs Cobol Net Express.
    I need two helps.
    1 - How can do to the Pro*Cobol cut the blanks on the right into PIC X Varying hosts variables ?
    For example :
    ..... LastName VARCHAR(20)
    ..... 05 LASTNAME PIC X(20) VARYING.
    The Pro*Cobol documentation say that precompile transform the elementary item LASTNAME to the group item bellow :
    05 LASTNAME.
    10 LASTNAME-LEN PIC S9(04) COMP.
    10 LASTNAME-ARR PIC X(20).
    When a string less than 20 is moved to LASTNAME-ARR, the exact string lenght is moved to the LASTNAME-LEN and the string is writen
    into DB without blanks on right.
    When a string is red from DB, the precompile write into LASTNAME-LEN the exact string lenght and the LASTNAME-ARR receive the
    string value without blanks on write.
    Occurs that when I compile the program the Pro*Cobol/Micro Focus don´t recognize LASTNAME-LEN and LASTNAME-ARR.
    Am I correct ? May I use any directive that resolve that ?
    2 - I need to check these step-by-step to write a text file generated from cobol into a BLOB column.
    The LOAD FROM FILE statement receive SQLCODE -22275 : Invalid LOB locator specified.
    Assumptions :
    MAG-RELAT-BFILE SQL-BFILE.
    MAG-RELAT-BLOB SQL-BLOB.
    The fiel R1401 exists in D:\Petros\NE\
    Source Code :
    MOVE 'D:\Petros\NE\' TO ALIAS
    MOVE 13 TO ALIAS-L
    MOVE 5 TO FILENAME-L
    MOVE 'R1401' TO FILENAME
    EXEC SQL
    ALLOCATE :IMAG-RELAT-BFILE
    END-EXEC.
    IF SQLCODE NOT EQUAL +0
    MOVE 'ERRO COMANDO ALLOCATE' TO WW-CA-MENSAGEM
    MOVE 'IMAG-RELAT-BFILE' TO WW-CA-ARQUIVO
    MOVE SQLCODE TO WW-ST-ARQUIVO
    MOVE 08 TO RETURNO-CODE
    PERFORM 999-TRATA-ERRO THRU 999-FIM
    END-IF.
    EXEC SQL
    LOB FILE SET :IMAG-RELAT-BFILE
    DIRECTORY = :ALIAS,
    FILENAME = :FILENAME
    END-EXEC.
    IF SQLCODE NOT EQUAL +0
    MOVE 'ERRO COMANDO LOB FILE SET' TO WW-CA-MENSAGEM
    MOVE 'IMAG-RELAT-BFILE' TO WW-CA-ARQUIVO
    MOVE SQLCODE TO WW-ST-ARQUIVO
    MOVE 08 TO RETURNO-CODE
    PERFORM 999-TRATA-ERRO THRU 999-FIM
    END-IF.
    EXEC SQL
    ALLOCATE :IMAG-RELAT-BLOB
    END-EXEC
    IF SQLCODE NOT EQUAL +0
    MOVE 'ERRO COMANDO ALLOCATE' TO WW-CA-MENSAGEM
    MOVE 'IMAG-RELAT-BLOB' TO WW-CA-ARQUIVO
    MOVE SQLCODE TO WW-ST-ARQUIVO
    MOVE 08 TO RETURNO-CODE
    PERFORM 999-TRATA-ERRO THRU 999-FIM
    END-IF.
    EXEC SQL
    LOB LOAD :TOTAL-BYTES
    FROM FILE :IMAG-RELAT-BFILE
    INTO :IMAG-RELAT-BLOB
    END-EXEC.
    IF SQLCODE NOT EQUAL +0
    MOVE 'ERRO COMANDO LOAD FFOM FILE' TO WW-CA-MENSAGEM
    MOVE 'IMAG-RELAT-BFILE, IMAG-RELAT-BLOB' TO WW-CA-ARQUIVO
    MOVE SQLCODE TO WW-ST-ARQUIVO
    MOVE 08 TO RETURNO-CODE
    PERFORM 999-TRATA-ERRO THRU 999-FIM
    END-IF.
    Thanks,

    907466 wrote:
    Hi,
    I´m using the Pro*Cobol pre-compile to execute SQL statements into programs Cobol Net Express.
    I started my career as a cobol programmer in 1981, and the last project I worked on before transitioning to DBA was implementing MF Cobol. It's been a number of years but ...
    I need two helps.
    1 - How can do to the Pro*Cobol cut the blanks on the right into PIC X Varying hosts variables ?
    For example :
    ..... LastName VARCHAR(20)
    ..... 05 LASTNAME PIC X(20) VARYING.
    The Pro*Cobol documentation say that precompile transform the elementary item LASTNAME to the group item bellow :
    05 LASTNAME.
    10 LASTNAME-LEN PIC S9(04) COMP.
    10 LASTNAME-ARR PIC X(20).
    When a string less than 20 is moved to LASTNAME-ARR, the exact string lenght is moved to the LASTNAME-LEN and the string is writen
    into DB without blanks on right.
    When a string is red from DB, the precompile write into LASTNAME-LEN the exact string lenght and the LASTNAME-ARR receive the
    string value without blanks on write.
    Occurs that when I compile the program the Pro*Cobol/Micro Focus don´t recognize LASTNAME-LEN and LASTNAME-ARR.
    Am I correct ? May I use any directive that resolve that ?
    I don't know if you are correct or not. Is the pre-compiler or compiler step throwing an error message? If you are correct, there should be an error message that you should share with us.
    2 - I need to check these step-by-step to write a text file generated from cobol into a BLOB column.
    The LOAD FROM FILE statement receive SQLCODE -22275 : Invalid LOB locator specified.
    Assumptions :
    MAG-RELAT-BFILE SQL-BFILE.
    MAG-RELAT-BLOB SQL-BLOB.
    The fiel R1401 exists in D:\Petros\NE\
    Source Code :
    MOVE 'D:\Petros\NE\' TO ALIAS
    MOVE 13 TO ALIAS-L
    MOVE 5 TO FILENAME-L
    MOVE 'R1401' TO FILENAME
    EXEC SQL
    ALLOCATE :IMAG-RELAT-BFILE
    END-EXEC.
    IF SQLCODE NOT EQUAL +0
    MOVE 'ERRO COMANDO ALLOCATE' TO WW-CA-MENSAGEM
    MOVE 'IMAG-RELAT-BFILE' TO WW-CA-ARQUIVO
    MOVE SQLCODE TO WW-ST-ARQUIVO
    MOVE 08 TO RETURNO-CODE
    PERFORM 999-TRATA-ERRO THRU 999-FIM
    END-IF.
    EXEC SQL
    LOB FILE SET :IMAG-RELAT-BFILE
    DIRECTORY = :ALIAS,
    FILENAME = :FILENAME
    END-EXEC.
    IF SQLCODE NOT EQUAL +0
    MOVE 'ERRO COMANDO LOB FILE SET' TO WW-CA-MENSAGEM
    MOVE 'IMAG-RELAT-BFILE' TO WW-CA-ARQUIVO
    MOVE SQLCODE TO WW-ST-ARQUIVO
    MOVE 08 TO RETURNO-CODE
    PERFORM 999-TRATA-ERRO THRU 999-FIM
    END-IF.
    EXEC SQL
    ALLOCATE :IMAG-RELAT-BLOB
    END-EXEC
    IF SQLCODE NOT EQUAL +0
    MOVE 'ERRO COMANDO ALLOCATE' TO WW-CA-MENSAGEM
    MOVE 'IMAG-RELAT-BLOB' TO WW-CA-ARQUIVO
    MOVE SQLCODE TO WW-ST-ARQUIVO
    MOVE 08 TO RETURNO-CODE
    PERFORM 999-TRATA-ERRO THRU 999-FIM
    END-IF.
    EXEC SQL
    LOB LOAD :TOTAL-BYTES
    FROM FILE :IMAG-RELAT-BFILE
    INTO :IMAG-RELAT-BLOB
    END-EXEC.
    IF SQLCODE NOT EQUAL +0
    MOVE 'ERRO COMANDO LOAD FFOM FILE' TO WW-CA-MENSAGEM
    MOVE 'IMAG-RELAT-BFILE, IMAG-RELAT-BLOB' TO WW-CA-ARQUIVO
    MOVE SQLCODE TO WW-ST-ARQUIVO
    MOVE 08 TO RETURNO-CODE
    PERFORM 999-TRATA-ERRO THRU 999-FIM
    END-IF.
    Thanks,So far you haven't shown us any symptoms, errors, etc. Just a description of what you are doing and a statement that you assume it won't work. Your executable code has a lot of reference to host variables that we can only assume a spelled correctly to match to variables you've declared in your data division. Are you going straight from submitting precompile to run-time, or are you using the very excellent interactive source-level debugger that is a prime feature of MF Cobol?

  • Writing chinese character into a file

    Hi,
    I need to write chinese characters into a file,I used FileOutputStream, using the method write(byte[] b)...
    whereby I will convert the chinese word into bytes....
    but it couldn't work...
    Please Help!!

    you can write the unicode hex string (e.g. 606D559C53D18D22 for Gong Xi Fa Chai) into a text file by using the following code
              PrintWriter out2 = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream("chinese_out.txt", false), "UTF-8")));
                   int countChineseChar = chineseHex.length()/4;
                   int index = 0;
                   String c = "";
                   int b;
                   for(int i=0; i<countChineseChar-1; i++)
                        c = new String(chineseHex.substring(index, index+4));
                        b = Integer.parseInt(c, 16);
                        out2.write(b);
                        index+=4;
    Note that the OutputStreamWriter uses the UTF-8 to encode the unicode hex. I'm assuming that the hex is fixed at 4 digits each character
    syam

  • How to use OCR Font A type by the time of writing some text into Pdf fil

    Hi,
    I am generating one pdf file in java. How can I use OCR Font A for text of pdf file ..Please can any one help where can I get OCR Font A and how to use that one in java ... I want to write some text into pdf file and that text should use OCR Font A family ...
    Thanks.

    This document shows how to disable OCR during conversion; just do the opposite: https://forums.adobe.com/docs/DOC-3062

  • How to writing the data into the file at the same frequency of data acquisition using myRIO

    Hi everyone,
    I have a question regarding data acquisition fequency and data recording frequency of myRIO. Hope you guys can help me out.
    Basically, I want to acquire voltage input at analog input 0 at the frequency of 1kHz and then write the data into a file (tdms format). 
    However, I always found there were only 55 or 56 data points recorded every second in the data file (see the excel sheet). 
    To confirm my data acquisition was performed at the correct frequency, I added a small function in the main loop to indicate the time spent between two acquisition events. 
    To my surprise, the period of data acquistion is correct (1ms or 1kHz) but there are only 55 or 56 data point per second recorded in the data file.
    How can I record every data point acquired by the analog input?
    Thank you!
    P.S. I am very new to myRIO. How can I manually set the system time for myRIO? The default time of my myRIO is wrong. 
    Best,
    Tengyang
    Attachments:
    test result.xlsx ‏16 KB
    Main with timed loop.vi ‏122 KB
    test result.xlsx ‏16 KB

    Have a look at the Jakarta POI project, they have a Java API for creating Word documents.
    http://jakarta.apache.org/poi/hwpf/index.html

  • How to get oracle 9i blob column into an itab  in sap using Native SQL

    Hi ,
    We are using SAP ECC 5.0  and we need to coonect to an oracle database ver 9i rel2.
    We need to get the data stored in a blob(pdf/jpeg) into an itab and later
    use it for futher processing.
    I am familiar with using native SQL and I wrote a stored procedure in the non sap oracle database to send the blob info into an internal table in sap.
    But the information is in hex format and the long raw of SAP does not handle this very well.
    Plz see my code below.
    data: itab_insp_drawing like zpicture_cluster(which is of type lraw - 7902 )
          occurs 100 with header line.
    EXEC SQL.
        EXECUTE PROCEDURE
           proc_get_insp_drawings  (
                   IN  :itab-aq_id,
                   IN  :itab-section_id,
                   IN  :t_in_position,
                   out :itab_insp_drawing-picture,
                   OUT :t_blob_length,
                   out :t_out_position,
                   OUT :t_status  )
       ENDEXEC.
      append itab_insp_drawing.
      while t_out_position < t_blob_length.
       EXEC SQL.
        EXECUTE PROCEDURE
           proc_get_insp_drawings  (
                   IN  :itab-aq_id,
                   IN  :itab-section_id,
                   IN  :t_in_position,
                   out :itab_insp_drawing-picture,
                   OUT :t_blob_length,
                   out :t_out_position,
                   OUT :t_status  )
       ENDEXEC.
       append itab_insp_drawing.
       endwhile.
    Any ideas of how to handle blobs from non sap oracle table. I need this blob into an itab in sap.
    Help appreciated.
    Thanks
    Mala

    Please refer the example in this link which deals with Oracle date format.
    You can finnd a command DECODE which is used for date formats. If you have a look at whole theory then you will get an idea.
    Link:[Bulk insert SQL command to transfer data from SAP to Oracle|http://sap.ittoolbox.com/groups/technical-functional/sap-dev/bulk-insert-sql-command-to-transfer-data-from-sap-to-oracle-cl_sql_connection-3780804]

  • Writing blob data to a file

    HI,
    I have a table with following structure
    Test_Mail(Attachment BLOB,Attachmentname varchar2(255),FileSize number)
    The data in the table is like
    Attachment|Attachmentname|FileSize
    BLOB|test.txt|1236
    I wants to read the data from the BLOB attachment in to new file.
    The data in the file is
    Ename|JOB|DEPTNO|SALARY
    ford|salesman|10|5555
    boye|salesman|10|3333
    smith|clerk|20|3000
    Iam using the following procedure to do the same
    create or replace
    procedure SAVE_TO_FILE as
    vblob blob;
    i2 number;
    amt number := 10000;
    len number;
    my_vr raw(10000);
    l_output utl_file.file_type;
    p_dir varchar2(30) default '/home/test';
    p_file varchar2(30) := 'output.txt';
    begin
    l_output := utl_file.fopen(p_dir, p_file,'w',32767);
    for l_cur in (SELECT ATTACHMENT vblob FROM test_email)
    loop
    len :=DBMS_LOB.GETLENGTH(l_cur.vblob);
    vblob := l_cur.vblob ;
    dbms_output.put_line('Length of the Column : ' || to_char(len));
    i2 := 1;
    if len < 10000 then
    DBMS_LOB.READ(vblob,len,i2,my_vr);
    utl_file.put(l_output,UTL_RAW.CAST_TO_VARCHAR2(my_vr) );
    else
    DBMS_LOB.READ(vblob,amt,i2,my_vr);
    utl_file.put(l_output, UTL_RAW.CAST_TO_VARCHAR2(my_vr) );
    end if;
    i2 := i2 + amt;
    while (i2 < len)
    loop
    dbms_output.put_line('i2 : ' || to_char(i2));
    DBMS_LOB.READ(vblob,amt,i2,my_vr);
    utl_file.put(l_output, UTL_RAW.CAST_TO_VARCHAR2(my_vr));
    utl_file.fflush(l_output);
    i2 := i2 + amt ;
    end loop;
    utl_file.fclose(l_output);
    end loop;
    commit;
    end SAVE_TO_FILE;
    The problem here is it is reading only 19 bytes and output is
    Ename|JOB|DEPTNO|SALAR
    can any one please help me in sloving this isssue??
    Thanks in advance
    Balaji tk

    Duplicate post.
    Re: Reading the data from BLOB column

  • Writing generated XML into a file after comparing with other XML

    Hi,
      I have completed the comparison of two XML now I have a requirement to concat these two xml but also need to append the XML with a status node that if after comparing the two XML output is Y or N so if it is Y then a node with
    <status>Y</status>
    <from table>t1</from table>
    then completing those task I need to write it in a file
    declare
        p_emp_info   CLOB;
      l_emp_tab        xmlsequencetype := xmlsequencetype();
    BEGIN
      FOR i IN (SELECT id from emp WHERE emp_name='ABC') LOOP
        l_emp_tab.extend;
        SELECT XMLELEMENT("ABCD",
               XMLELEMENT("id",i.id))
          INTO l_emp_tab(i)
          FROM dual;
    END LOOP;
      SELECT XMLELEMENT("EMP"
                           ,XMLAGG(t.column_value))
        INTO p_emp_info  
        FROM TABLE(l_emp_tab) t;
        --Dbms_Output.put_line(getclobval(1,2));
    EXCEPTION
        WHEN OTHERS THEN
       Dbms_Output.put_line(SQLCODE||sqlerrm);
    END ;
    I am using this query but it is giving me an error that expression is of wrong type  at this line {  INTO l_emp_tab(I) }
    I am unable to find out the error that what I am missing here !!

    You've changed the datatype of i from the example that Odie gave you in
    repeating nodes using FOR loop but when concating XML string then concating only last iteration of FOr loop ??
    In his example, i was a number.  In your above code, i is now the rowset for a cursor.
    You could rewrite your version to look like
    declare
      p_emp_info     XMLTYPE;
      l_emp_tab      xmlsequencetype := xmlsequencetype();
      l_pos          PLS_INTEGER;
      CURSOR c_info IS
        SELECT id
          from emp
         WHERE emp_name='ABC';
    BEGIN
      FOR r_info IN c_info LOOP
        l_emp_tab.extend;
        l_pos := c_info%ROWCOUNT;
        SELECT XMLELEMENT("ABCD",
               XMLELEMENT("id",r_info.id))
          INTO l_emp_tab(l_pos)
          FROM dual;
      END LOOP;
      SELECT XMLELEMENT("EMP"
                           ,XMLAGG(t.column_value))
        INTO p_emp_info 
        FROM TABLE(l_emp_tab) t;
      --Dbms_Output.put_line(p_emp_info.getclobval());
    END ;
    You can't use the c_info%ROWCOUNT in the INTO clause, hence the need for l_pos.
    Or you could rewrite it to be
    declare
      p_emp_info   XMLTYPE;
      l_clob       CLOB;
    BEGIN
      SELECT XMLElement("EMP",
               XMLAgg(XMLElement("ABCD",
                        XMLElement("id",e.id))))
        INTO p_emp_info
        FROM emp e
       WHERE emp_name = 'ABC';
      SELECT XMLSERIALIZE(DOCUMENT p_emp_info AS CLOB)
        INTO l_clob
        FROM DUAL;
      Dbms_Output.put_line(l_clob);
    END;
    Both produce the same XML.

  • Problems writing BLOB data into O8i (ADO and AppendChunk)

    We have a table where you want to store bianry data (BLOBs). I
    have used the LONG RAW datatype to store this information. Here
    is the code for the table:
    CREATE TABLE "CONTENTBLOBTABLE" (
    DIGEST NVARCHAR2(40) NOT NULL,
    BLOB LONG RAW,
    CHECK (DIGEST IS NOT NULL),
    PRIMARY KEY (DIGEST)
    Then we try to update this table with ADO 2.6 on a Windows 200
    machine with Oracle ODBC driver. Here is the relevant code
    snippet:
    // set the value of the field
    pRs->AddNew();
    pRs->Fields->GetItem("DIGEST")->PutValue(strDigest);
    pRs->Fields->GetItem("BLOB")->AppendChunk(varBLOB);
    if(!pRs->Update())
    C_LOG_CRITICAL(L"CC_CS_DAL::WriteBLOB - pRs->Update failed");
    *error = C_CS_CBT_ERROR;
    pRs->CancelUpdate();
    pRs->Close();
    m_pConn->Close();
    m_spObjectContext->SetAbort();
    return S_FALSE;
    OK, NO error occurs: no exception, HRESULT return values are all
    OK, method completes.
    BUT: there is no data in the table!?!?! When querying the exact
    same table we get an empty result!
    Any ideas please?
    Thanks,
    Christian

    Did you even get a reply to this message?

  • Emergency! Writing an object into a file (NotSerializableException)

    Hi, I am now working in a project. I came across a serialization problem which I am spending so many days and haven't gotten any solution.
    I assume that the problem is caused by the complexity of class design in a package. The saved object extends all of 9~11 classes in which some are abstract class, some are listening interface class, some are just normal class but extending from GUI components such as JTree, JFrame and so on. Besides static is spred over anywhere in the classes.
    code:(No problem here)
    output = new ObjectOutputStream( new eFileOutputStream( fileName ) );
    output.writeObject(prj);
    output.flush();
    Futher, the 'prj' object is proved to be very serializable as a result of "isSerializable()" function before writting in to a file. However it invokes IOExceptions, isn't it funny?
    ex:
    A--B--C--D--E
    |
    |
    F G H
    | |
    I J
    |
    prj
    In the example of above, is it possible to store all the state of objects A to J by storing prj so that I can re-construct the whole of objects relations and the members in them from the stored 'prj'?
    Back to the original problem, then...
    Do I have to get rid of all the static declarations of parent classes?
    Do I have to serialize each single classes one by one without being greedy tryint to store all of the state of objects linked to 'prj' at once?
    Do I have to get every single objects implemented 'Serializable' including abstruct and interface classes if they contains static declaration or someting unserializable?
    Please give me any help or hint, anything I am appreciate for.

    The problem is not very clear. Some code snippets might help. Especially the Exception details.Your object graph is somewhat confusing too.
    To answer your questions, the default Serialization (where the object prj, though extends java.io.Serializable, DOESN'T implement writeObject() and readObject() methods) will succeed only if all the reachable super classes in the graph are a. either implement Serializable or b. have no-argument constructors. In case of b., it's the responsibility of the object prj to re-establish the state of the parent classes from the serialized stream. You can do that by implementing writeObject() and readObject() methods themselves.
    The transient and static fields are never serialized. So if you want to preserve the value of a static field then you'll have to either a. explicitly serialize that field out to the ObjectOutputStream and read it back from the ObjectInputStream in the writeObject() and readObject() methods or b. using reflection where you can get the Class name and get the static field value from the corresponding 'Class' data type also using reflection (object.getClass().getField("fieldName").getValue(null)).

  • How to convert blob data into clob using plsql

    hi all,
    I have requirement to convert blob column into clob .
    version details
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - Production
    PL/SQL Release 11.1.0.7.0 - Production
    CORE     11.1.0.7.0     Production
    TNS for 32-bit Windows: Version 11.1.0.7.0 - Production
    NLSRTL Version 11.1.0.7.0 - Production
    DECLARE
       v_blob      temp.blob_column%TYPE;------this is blob data type column contains  (CSV file which is  inserted  from screens)
       v_clob      CLOB; --i want to copy blob column data into this clob
       v_warning   NUMBER;
    BEGIN
       SELECT blob_column
         INTO v_blob
         FROM temp
        WHERE pk = 75000676;
       DBMS_LOB.converttoclob (dest_lob          => v_clob,
                               src_blob          => v_blob,
                               amount            => DBMS_LOB.lobmaxsize,
                               dest_offset       => 1,
                               src_offset        => 1,
                               blob_csid         => 1, -- what  is the use of this parameter
                               lang_context      => 1,
                               warning           => v_warning
       DBMS_OUTPUT.put_line (v_warning);
    EXCEPTION
       WHEN OTHERS
       THEN
          DBMS_OUTPUT.put_line (SQLCODE);
          DBMS_OUTPUT.put_line (SQLERRM);
    END;I am not getting what is the use of blob_csid , lang_context parameters after going the trough the documentation .
    Any help in this regard would be highly appreciated .......
    Thanks
    Edited by: prakash on Feb 5, 2012 11:41 PM

    Post the 4 digit Oracle version.
    Did you read the Doc for DBMS_LOB.CONVERTTOCLOB? - http://docs.oracle.com/cd/B28359_01/appdev.111/b28419/d_lob.htm
    The function can convert data from one character set to another. If the source data uses a different character set than the target you need to provide the character set id of the source data.
    The blob_csid parameter is where you would provide the value for the source character set.
    If the source and target use the same character set then just pass zero. Your code is passing a one.
    >
    General Notes
    You must specify the character set of the source data in the blob_csid parameter. You can pass a zero value for blob_csid. When you do so, the database assumes that the BLOB contains character data in the same character set as the destination CLOB.
    >
    Same for 'lang_context' - your code is using 1; just use 0. It is an IN OUT
    >
    lang_context
    (IN) Language context, such as shift status, for the current conversion.
    (OUT) The language context at the time when the current conversion is done.
    This information is returned so you can use it for subsequent conversions without losing or misinterpreting any source data. For the very first conversion, or if do not care, use the default value of zero.

Maybe you are looking for