Convert clob to xmltype

Hi
How to convert data CLOB datatype to XMLTYPE Datatype
Ex: field col1 has clob data type
any possible to convert col1 in target table col1 xmltype datatype
Regards,
Venkat

Hi Venkat,
Please try the following:
CREATE TABLE CLOBTABLE (
CLOBCOL1 CLOB
INSERT INTO clobtable VALUES ('<?xml version="1.0"?> <EMP> <EMPNO>2</EMPNO> <ENAME>Sumeet</ENAME> </EMP>');
CREATE OR REPLACE FUNCTION to_xmltype (clobcol CLOB) RETURN XMLTYPE AS
BEGIN
RETURN XMLType(clobcol);
END;
SELECT to_xmltype(clobcol) FROM clobtab;

Similar Messages

  • How to convert CLOB to XMLType ??

    Hi,
    I created a table XML_TAB as
    SQL> desc xml_tab;
    Name Null? Type
    DOCID NUMBER
    DTD CLOB
    XMLDOC CLOB
    VALID NUMBER
    and I inserted a record in the table.
    Now the file inserted at the column XMLDOC, I want to convert it to XMLType. How can I do that.
    Some docs says to user XMLType.createXML function......
    But when I did it....................
    SQL> select xmltype.createxml(xmldoc) from xml_tab
    ERROR:
    ORA-31011: XML parsing failed
    ORA-19202: Error occurred in XML processing
    LPX-00210: expected '<' instead of '<'
    Error at line 1
    ORA-06512: at "SYS.XMLTYPE", line 0
    ORA-06512: at line 1
    What could be the cause of the problem? Am I doing it in a correct way?
    -- Jitendra

    The main difference between CLOB and XMLType is that XMLType always contain a well formed XML document.
    So if CLOB doesn't complain , then XMLType does.

  • Convert CLOB to XMLType in SELECT statement ?

    Hi XML Xperts,
    In my Oracle 9.2.0.3 I have 1 table (tab1) with 2 cols (col1 as XMLType and col2 as CLOB). I Inserted in both fields the following same XML data :
    <?xml version="1.0"?>
    <TABLE_NAME>MY_TABLE</TABLE_NAME>
    With the following statement, I can get the data from col1 which is a XMLType column :
    SELECT a.col1.extract('//TABLE_NAME/text()').getStringVal() AS "Table Name"
    FROM tab1 a
    WHERE a.col1.existsNode('/TABLE_NAME') = 1;
    How to get the same data FROM col2 whcih is a CLOB column ? Is it possible to transform the CLOB to XMLType in the SELECT statement ?
    Note : I cannot change the type of the colulmn col2 to XMLType
    Thanks in advance.
    Phil

    I tested it in 10g and it seems to be OK.
    create table clobtoxml(xmldata clob);
    insert into clobtoxml
    values('<RootE><FirstNode>This is CLOB data to XML</FirstNode></RootE>');
    commit;
    select sys.xmltype(xmldata).extract('/RootE/FirstNode/text()').getStringVal() from clobtoxml;
    This is CLOB data to XML
    select sys.xmltype(xmldata).extract('/*') from clobtoxml;
    <RootE>
    <FirstNode>This is CLOB data to XML</FirstNode>
    </RootE>
    Ben

  • Conversion of a Base64EncodedXML CLOB to XMLTYPE

    I have an xml file which is base64 encoded and the base64 encoded file is stored as a clob. I want to do all the manipulation in PL/SQL and modify the clob column with one of xmltype
    Heres the steps I've got so far:
    i) convert the clob to a blob using dbms_lob.converttoclob
    ii) Since this is now in binary format I'm asusming that I don't need to cast to raw
    iii) decode the binary file using UTL_ENCODE.base64_decode
    iv) add an additional column  temp_xml as type xml_type
    v) update the temp_xml column with the values of the original column.
    update <tablename>
                   set temp_xml = xmltype(orig_clob_column) vi) At this stage I will see if I can read the xml in the new column and if all is successful, I will drop the orig_clob_column and rename temp_xml to orig_clob_column.
    If I've missed anything or anyone's got some gotchas for me, it would be appreciated.
    Message was edited by:
    Keith Jamieson
    Message was edited by:
    Keith Jamieson

    I am using Oracle 11g Windows and based on the example here:
    http://www.peakretrieval.com/plsql/Chapter16/Convert.sql
    create or replace PROCEDURE CONVERT_ME (
       v_blob_or_clob IN NUMBER,
       v_blob IN OUT BLOB,
       v_clob IN OUT CLOB,
       v_amount IN OUT NUMBER,
       v_blob_offset IN OUT NUMBER,
       v_clob_offset IN OUT NUMBER,
       v_lang_context IN OUT NUMBER,
       v_warning OUT NUMBER)
    AS
    BEGIN
       DBMS_LOB.OPEN(v_blob, DBMS_LOB.LOB_READWRITE);
       DBMS_LOB.OPEN(v_clob, DBMS_LOB.LOB_READWRITE);
       IF v_blob_or_clob = 0
       THEN
       DBMS_LOB.CONVERTTOBLOB(v_blob,
                              v_clob,
                              v_amount,
                              v_blob_offset,
                              v_clob_offset,
                              1,
                              v_lang_context,
                              v_warning);
       ELSE
       DBMS_LOB.CONVERTTOCLOB(v_clob,
                              v_blob,
                              v_amount,
                              v_clob_offset,
                              v_blob_offset,
                              1,
                              v_lang_context,
                              v_warning);
       END IF;
       DBMS_LOB.CLOSE(v_blob);
       DBMS_LOB.CLOSE(v_clob);
    END;When I run this sample code
    DECLARE
       v_clob_or_blob NUMBER;
       v_blob_locator BLOB;
       v_clob_locator CLOB;
       v_blob_offset NUMBER;
       v_clob_offset NUMBER;
       v_lang_context NUMBER := DBMS_LOB.DEFAULT_LANG_CTX;
       v_warning NUMBER;
       v_string_length NUMBER(10);
       v_source_locator BLOB;
       v_destination_locator BLOB;
       v_amount PLS_INTEGER;
       v_string CLOB;
    BEGIN
       -- CONVERT CLOB TO BLOB
       SELECT description
       INTO v_clob_locator
       FROM book_samples
       WHERE book_sample_id = 1
       FOR UPDATE;
       SELECT misc
       INTO v_blob_locator
       FROM book_samples
       WHERE book_sample_id = 1
       FOR UPDATE;
       v_string_length := DBMS_LOB.GETLENGTH(v_blob_locator);
       v_amount := DBMS_LOB.GETLENGTH(v_clob_locator);
       DBMS_OUTPUT.PUT_LINE('The initial length of the BLOB is: '||v_string_length);
            v_clob_or_blob := 0; -- Convert clob to blob
            v_clob_offset := 1;
            v_blob_offset := 1;
            CONVERT_ME(v_clob_or_blob,
                    v_blob_locator,
                    v_clob_locator,
                    v_amount,
                    v_blob_offset,
                    v_clob_offset,
                    v_lang_context,
                    v_warning);
       v_string_length := DBMS_LOB.GETLENGTH(v_blob_locator);
       DBMS_OUTPUT.PUT_LINE('The length of the BLOB post-conversion is: '||v_string_length);
       -- COPY BLOB FOR ONE ROW TO BLOB IN ANOTHER
       v_source_locator := v_blob_locator;
       SELECT misc
       INTO v_destination_locator
       FROM book_samples
       WHERE book_sample_id = 2
       FOR UPDATE;
       DBMS_LOB.COPY(v_destination_locator, v_source_locator, 32768, 1, 1);
       v_string_length := DBMS_LOB.GETLENGTH(v_destination_locator);
       DBMS_OUTPUT.PUT_LINE('The length of the BLOB post-copy is: '||v_string_length);
       -- COPY BLOB FOR RECORD 2 BACK TO A CLOB
       SELECT description
       INTO v_clob_locator
       FROM book_samples
       WHERE book_sample_id = 2
       FOR UPDATE;
       SELECT misc
       INTO v_blob_locator
       FROM book_samples
       WHERE book_sample_id = 2
       FOR UPDATE;
       v_string_length := DBMS_LOB.GETLENGTH(v_clob_locator);
       v_amount := DBMS_LOB.GETLENGTH(v_blob_locator);
       DBMS_OUTPUT.PUT_LINE('The initial length of the CLOB (record 2) is: '||v_string_length);
            v_clob_or_blob := 1; -- Convert blob to clob
            v_clob_offset := 1;
            v_blob_offset := 1;
            CONVERT_ME(v_clob_or_blob,
                    v_blob_locator,
                    v_clob_locator,
                    v_amount,
                    v_clob_offset,
                    v_blob_offset,
                    v_lang_context,
                    v_warning);
       v_string_length := DBMS_LOB.GETLENGTH(v_clob_locator);
       SELECT description
       INTO v_string
       FROM book_samples
       WHERE book_sample_id = 2;
       DBMS_OUTPUT.PUT_LINE('The length of the CLOB post-conversion is: '||v_string_length);
       DBMS_OUTPUT.PUT_LINE('     ');
       DBMS_OUTPUT.PUT_LINE('The converted CLOB');
       DBMS_OUTPUT.PUT_LINE('==================');
       DBMS_OUTPUT.PUT_LINE(SUBSTR(v_string,1,150));
       DBMS_OUTPUT.PUT_LINE(SUBSTR(v_string,151,300));
    EXCEPTION
       WHEN OTHERS
       THEN
          DBMS_OUTPUT.PUT_LINE('I''M BROKEN ... FIX ME!');
          DBMS_OUTPUT.PUT_LINE(SQLERRM);
    END;I get the following error:
    Length of blob before conversion
    The conver_me procedure is broken ...
    ORA-06502: PL/SQL: numeric or value error: invalid LOB locator specified: ORA-22275
    Length of blob after conversion

  • Convert clob to blob

    Anyone know an easy way to convert clob data to blob data?
    We upgraded a client to 8.1.7.2 and now we can no longer store MS-Word templates to the RDBMS.
    I deduce this is because MS-Word templates are binary files.
    Earlier versions of 8.1.7 and 8.1.6 allowed us to do this. However, this is no longer the case.
    Some of my clob rows are over 6 meg.
    I have written some PL/SQL code to basically retrieve the clob data in cursor, loops through the clob in 32767 blocks,
    performing dbms_lob.substr, converts that data to hex(major pain), & then write the blocks using dbmbs_lob.write.
    I keep getting the proverbial "ORA-06502: PL/SQL: numeric or value error: invalid LOB locator specified: ORA-22275".
    Does anyone see flaws in my approach and might have an easier solution?
    Thanks!

    Here's my code:
    REATE OR REPLACE
    PROCEDURE p_load_clob_to_blob IS
    * Name:           p_load_clob_to_blob
    * Parameters: None
    * Purpose: This procedure loads the narr_blob column in the narr table_text with clob data from the
    * narr column.
    * Notes: This procedure assumes that narr table has been altered with narr_blob column added.
    * See the SQL below:
    *               alter table narr_text add (narr_blob blob);
    * Once this procedure executes, the table must altered to drop the narr_text clob column,
    * recreate the narr_text as blob, & then repopulate narr_text. See the SQL below:
    *                     alter table narr_text drop column narr;
    *                    alter table narr_text add (narr blob);
    *                    update narr_text set narr = narr_blob;
    *                    commit;
    * Called By: Sys Admin
    * CHANGE LOG
    * Changed By Date Change Description
    * EAO          01/16/02 Created.
    rec_read      INTEGER;
    rec_update      INTEGER;
    write_cnt INTEGER;
    write_amount BINARY_INTEGER;
    write_offset INTEGER;
    write_loop INTEGER;
    total_length      NUMBER;
    total_written      NUMBER;
    buffer VARCHAR2(32767);
    bbuffer RAW(32767);
    temp_narr_id NUMBER;
    max_loop               INTEGER;
    cx                    CLOB;
    bx                    BLOB;
    bx2                    BLOB;
    cur_evt               varchar2(50); -- current event
    v_err_descr          varchar2(256);
    i INTEGER;
    hex                    varchar(32767);
    CURSOR c_load_narr_clob IS
         SELECT narr, narr_id
         FROM narr_text
         where narr_id = 6366;
    BEGIN
    insert_event_log('', 'p_load_clob_to_blob', '', '', '', 'p_load_clob_to_blob started', '');
    rec_read := 0;
    rec_update := 0;
    ---Fill file
    insert_event_log('', 'p_load_clob_to_blob ','c_load_narr_clob ', '', 'S', 'c_narr_clob started', '');
    FOR csr IN c_load_narr_clob LOOP      
         cur_evt := 'Select narr from narr table: ';
         rec_read := rec_read + 1;
         write_loop := 1;
         write_cnt := 0;
         write_offset := 1;           
         total_written := 0;     
         cx := csr.narr;
    bx := empty_blob();          
         total_length := DBMS_LOB.GETLENGTH(cx);
         max_loop := (total_length / 32767) + 1;
         if (total_length <= 32767) THEN
              write_amount := total_length;
         ELSE
              write_amount := 32767;
         END IF;
    dbms_output.put_line('Length=' || to_char(total_length) || ' Max loop=' || to_char(max_loop) || ' Write Amount=' || to_char(write_amount));
         temp_narr_id := csr.narr_id;
         while write_cnt < max_loop
         loop
    --FOR write_loop in 1..max_loop LOOP
              delete temp_blob;
              delete temp_raw;
              commit;
              cur_evt := 'Dbms_lob.substr: ';
              dbms_output.put_line(cur_evt);
    buffer := DBMS_LOB.SUBSTR(cx, write_amount, write_offset);
              dbms_output.put_line('Write Amount='|| to_char(write_amount) || ' Write Offset=' || to_char(write_offset) );
    cur_evt := 'Hex to Raw Assigment: ';
              dbms_output.put_line(cur_evt);
              bbuffer := null;
              for i in 1..write_amount loop
                   hex := numtohex(ascii(substrb(buffer,i,1)));
                   bbuffer := bbuffer || hextoraw(hex);
              end loop;
    cur_evt := 'Insert temp_raw: ';
              dbms_output.put_line(cur_evt);
              insert into temp_raw(rx)
                   values (bbuffer);
              commit;
    cur_evt := 'Insert temp_blob: ';
              dbms_output.put_line(cur_evt);
              execute immediate 'insert into temp_blob(bx)
                   select TO_LOB(rx) from temp_raw';
              commit;
              cur_evt := 'Select bx2: ';
              dbms_output.put_line(cur_evt);
              bx2 := empty_blob();
              select bx into bx2 from temp_blob;
              cur_evt := 'Dbms_lob.append: ';
              dbms_output.put_line(cur_evt);
              dbms_lob.append(bx, bx2);
         dbms_output.put_line('Write Amount='|| to_char(write_amount) || ' Write Offset=' || to_char(write_offset) );
              write_offset := write_offset + write_amount;
              total_written := total_written + write_amount;
              write_cnt := write_cnt + 1;
              if (write_cnt = max_loop) then
              write_amount := total_length - total_written;
              end if;
    END LOOP;
    dbms_output.put_line('Total_written = ' || to_char(total_written) );
         cur_evt := 'Upd narr_blob in narr table: ';
         update narr_text
         set narr_blob = bx
         where narr_id = temp_narr_id;
         rec_update := rec_update + 1;
         commit;
    END LOOP;
    insert_event_log('', 'p_load_clob_to_blob ','c_load_narr_clob ', '', 'C', 'c_narr_clob completed', '');
    dbms_output.put_line('Records read=' || to_char(rec_read) || ' Records updated=' || to_char(rec_update) );
    insert_event_log('', 'p_load_clob_to_blob', '', '', '', 'p_load_clob_to_blob ended', '');
    EXCEPTION
         WHEN OTHERS THEN
         Rollback;
         v_err_descr := 'FATAL ERROR OCCURRED -'||cur_evt||sqlerrm;
         dbms_output.put_line (v_err_descr);
    END;
    FUNCTION numtohex(v_hex number) return varchar2
    is
    hex varchar2(4);
    num1 number;
    num2 number;
    begin
    num1 := trunc(v_hex/16);
    num2 := v_hex-(num1*16);
    if ( num1 >= 0 and num1 <= 9 ) then
    hex := hex||to_char(num1);
    end if;
    if num1 = 10 then hex := hex||'A'; end if;
    if num1 = 11 then hex := hex||'B'; end if;
    if num1 = 12 then hex := hex||'C'; end if;
    if num1 = 13 then hex := hex||'D'; end if;
    if num1 = 14 then hex := hex||'E'; end if;
    if num1 = 15 then hex := hex||'F'; end if;
    if ( num2 >= 0 and num2 <= 9 ) then
    hex := hex||to_char(num2);
    end if;
    if num2 = 10 then hex := hex||'A'; end if;
    if num2 = 11 then hex := hex||'B'; end if;
    if num2 = 12 then hex := hex||'C'; end if;
    if num2 = 13 then hex := hex||'D'; end if;
    if num2 = 14 then hex := hex||'E'; end if;
    if num2 = 15 then hex := hex||'F'; end if;
    return hex;
    end;

  • Convert clob to string?

    hi all,
    i'm having a problem getting the returnvalue of a storedproc. i'm using oracle database and created an oracle function that returns a clob data. unfortunately in vb.net, it won't accept clob format. if i change the returnvalue to varchar2 format it works fine.
    is there a way to convert clob into string?
    thanks.
    p.s.
    i'm using clob datatype because i need to return a large amount of characters (basically DDL statements like Creating tables with about a hundred partition more or less, also for creating a view with a very large text).

    It should be possible since Value is a string type property. Say if your OracleClob object name is clob1 then it should be possible to write something like -
    string str = clob1.Value;//C# syntax
    If you are using OracleParameter's Value property then you will have to do ".Value" twice as shown below -
    OracleParameter paramHavingClobInIt;
    string str = (paramHavingClobInIt.Value as OracleClob).Value; //C# syntax

  • Any way to convert CLOB to string in DB2?

    I'm trying to provide report names in audit reports.
    Is there any way to convert CLOB (AUDIT_DETAL.DETAIL_TEXT) to string?
    We use BO XI R3 on DB2 v.9.
    Thank you.

    949767 wrote:
    Is there any way to convert PDF document in to Tiff format with inbuilt IBR features?
    In our Webcenter Portal app, we create the PDF document with the content of ADF pages and check it in UCM using RIDC api.
    There will some batch job which will retrieve the documents from UCM and send them to client internal Document management system. The client / batch job will only process TIFF files. So we need a way to convert the PDF into TIFF. We are okie to have both PDF and TIFF stored in UCM.
    When i have done research, i could only see components like PDFexport or TIFFConverter which only converts the other formats into PDF. But i am expecting a reverse conversion. Is it possible ? ThanksYa actually I got a tool that could [convert pdf | http://www.allbestapp.com/products/pdf-converter.html] to other formats, including jpg and tiff. that may fit your need.
    You could take a shot through the link above.
    Edited by: user13548958 on 2012-8-23 上午10:49
    Edited by: user13548958 on 2012-8-23 上午10:52

  • How to convert CLOB to BLOB with SQL Developer migration wizard?

    Hi,
    According to our requirement, we need to only migrate data from SQL Server 2008 to Oracle 11. I use the SQL Developer 3.0.04 migration wizard to do it.
    I do migration from SQL Server (database name: SCDS41P2) to Oracle (User name: HCDS41P2).
    My migration steps are as below: (I need to modify the target schema, so I add the steps 2) and step 3) )
    1) Do migration by SQL Developer migration wizard;
    2) Remove the Converted Database Objects node from migration project;
    3) Re-do convert by SQL Developer migration wizard (contains changing the target schema);
    When do step 1), the DBO_SCDS41P2 user is created automatically. CLOBTOBLOB_SQLDEVELOPER procedure is also created in this user.
    I continued to run step 2) and step 3) with online mode. And find the table data which contains BLOB column can be moved into the target table. But from the Logging Page, I can't see the other detailed error info, so that I can't check which tables don't move data successfully.
    Could you please tell me where the detail log file (e.g. contains every table's migration status) is if I use the online mode?
    Additional, If I use offline mode to do step 3), I found the CLOB data can't be converted into BLOB automatically. Because in the load script (that is oracle_ctl.bat), only copy the source data to the CLOB column. After copy, it don't deal with the converting from CLOB to BLOB.
    So could you please tell me how to convert CLOB to BLOB with offline mode?
    Thanks so much.

    Hi,
    For your first question about logging - after the migration there will be an entry in the right hand panel for the migration project. If you open this there are various fields that give information about the status of each part of the migration. Does this give you the information you need ?
    For the second problem about offline moving blob data have a look at the SQL*Developer documentation -
    Oracle® SQL Developer User’s Guide Release 3.0
    in the section -
    2.2.8.1.4 Populating the Destination Database Using the Data Files
    which describes the problem and how to get round it.
    Regards,
    Mike
    Edited by: mkirtley on Aug 12, 2011 10:49 AM

  • How to convert clob to blob

    hi
    tell me some thong how we can convert clob to blob

    You can use my procedure
    create or replace procedure CLOB2BLOB (p_clob in out nocopy clob, p_blob in out nocopy blob) is
    -- transforming CLOB &#226; BLOB
    l_off number default 1;
    l_amt number default 4096;
    l_offWrite number default 1;
    l_amtWrite number;
    l_str varchar2(4096 char);
    begin
    begin
    loop
    dbms_lob.read ( p_clob, l_amt, l_off, l_str );
    l_amtWrite := utl_raw.length ( utl_raw.cast_to_raw( l_str) );
    dbms_lob.write( p_blob, l_amtWrite, l_offWrite,
    utl_raw.cast_to_raw( l_str ) );
    l_offWrite := l_offWrite + l_amtWrite;
    l_off := l_off + l_amt;
    l_amt := 4096;
    end loop;
    exception
    when no_data_found then
    NULL;
    end;
    end;
    Best regards, Victor

  • Converting CLOB to BLOB

    I am trying to convert clob into blob through following code.
    CREATE OR REPLACE FUNCTION clob_to_blob (clob_in IN CLOB)
    RETURN BLOB
    AS
    v_blob BLOB;
    v_varchar RAW(32767);
    v_start BINARY_INTEGER := 1;
    v_buffer BINARY_INTEGER := 32767;
    BEGIN
    FOR i IN 1..CEIL(DBMS_LOB.GETLENGTH(clob_in) / v_buffer)
    LOOP
    v_varchar := UTL_RAW.CAST_TO_RAW(DBMS_LOB.SUBSTR(clob_in, v_buffer, v_start)) ;
    DBMS_OUTPUT.PUT_LINE('DATA :' ||DBMS_LOB.SUBSTR(clob_in, v_buffer, v_start));
    DBMS_OUTPUT.PUT_LINE(' V_VARCHAR :'|| v_VARCHAR);
    DBMS_OUTPUT.PUT_LINE(' V_VARCHAR LENGTH :'|| LENGTH(v_VARCHAR));
    DBMS_LOB.WRITEAPPEND(v_blob, LENGTH(v_VARCHAR), v_varchar);
    DBMS_OUTPUT.PUT_LINE('after append');
    v_start := v_start + v_buffer;
    END LOOP;
    RETURN v_blob;
    END clob_to_blob;
    calling code:
    declare
    var clob;
    begin
    var:='3433534534de';
    testblob(var);
    end;
    It gives me following error:
    declare
    ERROR at line 1:
    ORA-21560: argument 2 is null, invalid, or out of range
    i don't know whats the prob?
    thanx

    dbms_lob.writeappend expects a real lob locator, which you can only get by selecting from a lob column.
    create table blobtab (b blob);
    insert into blobtab values (empty_blob());
    CREATE OR REPLACE FUNCTION clob_to_blob (clob_in IN CLOB)
    RETURN BLOB
    AS
    v_blob blob;
    v_varchar RAW(32767);
    v_start BINARY_INTEGER := 1;
    v_buffer BINARY_INTEGER := 32767;
    BEGIN
    select b into v_blob from blobtab;
    FOR i IN 1..CEIL(DBMS_LOB.GETLENGTH(clob_in) / v_buffer)
    LOOP
    v_varchar := UTL_RAW.CAST_TO_RAW(DBMS_LOB.SUBSTR(clob_in, v_buffer, v_start)) ;
    DBMS_OUTPUT.PUT_LINE(' DATA :' || DBMS_LOB.SUBSTR(clob_in, v_buffer, v_start));
    DBMS_OUTPUT.PUT_LINE(' V_VARCHAR :' || v_VARCHAR);
    DBMS_OUTPUT.PUT_LINE(' V_VARCHAR LENGTH :' || utl_raw.LENGTH(v_VARCHAR));
    DBMS_LOB.WRITEAPPEND(v_blob, utl_raw.LENGTH(v_VARCHAR), v_varchar);
    DBMS_OUTPUT.PUT_LINE('after append');
    v_start := v_start + v_buffer;
    END LOOP;
    RETURN v_blob;
    END clob_to_blob;
    declare
    blobvar blob;
    begin
    blobvar := clob_to_blob(dbms_xmlgen.getXML('select 1 from dual'));
    end;
    /

  • Converting CLOB to BLOB at once

    Hello all!
    I have to convert CLOB to BLOB in my application. My CLOB contains XML document built with dbms_xmldom, an I need to put it into column of type BLOB. Knowing several ways to do it, I'm searching for the best one. So I considered the folowing:
    - Size of XML data can be more then 4000 bytes.
    - I can convert it "piecewise", copying through varchar2 and raw buffers by chunks. But this is not efficient for me.
    - I can write CLOB to file, then read it into BLOB. But it is not efficient too.
    - I can not change column type to CLOB since it may contain other BLOB data, not XML.
    Actually, I need a way to "cast" CLOB data as binary data when inserting into table. I believe Oracle must have it, but where?
    I'll be very grateful for help from anyone.
    P.S. Using Oracle 9.2

    You could use UTL_RAW.CAST_TO_RAWhttp://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96612/u_raw2.htm#998330
    The XML data can be 32k (the varchar2 limit in PLSQL is 32k, not 4000 bytes)
    If your documents exceeds 32k you need process chunks

  • How to convert CLOB data (now it is in html format) to Normal text format

    Hi,
    Can anybody let me know the solution for how to convert CLOB data into normal Text.In my case the table column having CLOB datatype and the data is in html format.when i run the report the column is displaying html tags .Now i need to convert that html tags into normal text.
    Pl. let me know if any one know the solution.
    Regards,
    Thulasi.K

    LONG has been depricated since 8i so I don't believe there is a general solution to go backwards short of reloading the data.
    Justin

  • CLOB Vs XMLTYPE

    Hi Guys,
    In one of my applications , From the front end we are getting XML data and storing the xml data in the col of table which is CLOB type .
    Today one of the application developer told that directly we can store the xml data into the data base.Could any one tell me the difference in storing the data in the clob and xml
    and also what is the advantages of using xml over clob data type.
    Any suggestions will be highly appreciated.
    Thanks,
    Prafulla

    Prafulla wrote:
    Hi Guys,
    In one of my applications , From the front end we are getting XML data and storing the xml data in the col of table which is CLOB type .
    Today one of the application developer told that directly we can store the xml data into the data base.Could any one tell me the difference in storing the data in the clob and xml
    and also what is the advantages of using xml over clob data type.
    Any suggestions will be highly appreciated.
    Thanks,
    PrafullaXMLTYPE is based on the CLOB datatype under the hood. CLOB simply stores a whole stream of characters in one large chunk and you need to use the DBMS_LOB package to pull out any sort of structured information from that CLOB. XMLTYPE on the other hand understands that the content is XML and provides various methods for accessing the data as well as SQL being able to access the XML in a structured manner too.
    For example, if you have some XML in an XMLTYPE, you can use the XMLTABLE keyword in SQL to extract the data from it e.g..
    WITH t as (select XMLTYPE('
    <RECSET>
      <REC>
        <COUNTRY>1</COUNTRY>
        <POINT>1800</POINT>
        <USER_INFO>
          <USER_ID>1</USER_ID>
          <TARGET>28</TARGET>
          <STATE>6</STATE>
          <TASK>12</TASK>
        </USER_INFO>
        <USER_INFO>
          <USER_ID>5</USER_ID>
          <TARGET>19</TARGET>
          <STATE>1</STATE>
          <TASK>90</TASK>
        </USER_INFO>
      </REC>
      <REC>
        <COUNTRY>2</COUNTRY>
        <POINT>2400</POINT>
        <USER_INFO>
          <USER_ID>3</USER_ID>
          <TARGET>14</TARGET>
          <STATE>7</STATE>
          <TASK>5</TASK>
        </USER_INFO>
      </REC>
    </RECSET>') as xml from dual)
    -- END OF TEST DATA
    select x.country, x.point, y.user_id, y.target, y.state, y.task
    from t
        ,XMLTABLE('/RECSET/REC'
                  PASSING t.xml
                  COLUMNS country NUMBER PATH '/REC/COUNTRY'
                         ,point   NUMBER PATH '/REC/POINT'
                         ,user_info XMLTYPE PATH '/REC/*'
                 ) x
        ,XMLTABLE('/USER_INFO'
                  PASSING x.user_info
                  COLUMNS user_id NUMBER PATH '/USER_INFO/USER_ID'
                         ,target  NUMBER PATH '/USER_INFO/TARGET'
                         ,state   NUMBER PATH '/USER_INFO/STATE'
                         ,task    NUMBER PATH '/USER_INFO/TASK'
                 ) y
       COUNTRY      POINT    USER_ID     TARGET      STATE       TASK
             1       1800          1         28          6         12
             1       1800          5         19          1         90
             2       2400          3         14          7          5It uses XQuery expressions to reference the data, so you can reference attributes of the XML elements as well as their values, and you can also use namespaces if those are needed. The above is just a simple example with some nested repeating groups.
    If you tried to extract that data using a CLOB, you'd struggle to do that in SQL easily.

  • How to convert clob column to long

    Hi,
    Is there any way to convert clob column to long.
    Here below is my scenario..
    Instead of using substr function
    CREATE OR REPLACE PROCEDURE proc AS
    sql2 clob := '';
    sqlstring1 LONG;
    sqlstring2 LONG;
    sqlstring3 LONG;
    sqlstring4 LONG;
    sqlstring5 LONG;
    sqlstring6 LONG;
    sqlstring7 LONG;
    sqlstring8 LONG;
    sqlstring9 LONG;
    sqlstring10 LONG;
    BEGIN
    FOR sql1 IN (SELECT info FROM emp)
    LOOP
    sql2 := sql1.sql_string;
    sqlString1 := dbms_lob.SUBSTR(sql2, 8000, 1);
    sqlString2 := dbms_lob.SUBSTR(sql2, 8000, 8001);
    sqlString3 := dbms_lob.SUBSTR(sql2, 8000, 16001);
    sqlString4 := dbms_lob.SUBSTR(sql2, 8000, 24001);
    sqlString5 := dbms_lob.SUBSTR(sql2, 8000, 32001);
    sqlString6 := dbms_lob.SUBSTR(sql2, 8000, 40001);
    sqlString7 := dbms_lob.SUBSTR(sql2, 8000, 48001);
    sqlString8 := dbms_lob.SUBSTR(sql2, 8000, 56001);
    sqlString9 := dbms_lob.SUBSTR(sql2, 8000, 64001);
    sqlString10 := dbms_lob.SUBSTR(sql2, 8000, 72001);
    EXECUTE IMMEDIATE sqlString1 || sqlString2 || sqlString3 ||
    sqlString4 || sqlString5 || sqlString6 ||
    sqlString7 || sqlString8 || sqlstring9 ||
    sqlstring10;
    END LOOP;
    COMMIT;
    END proc;
    Any help really appreciated
    Thanks

    We cannot execute clob dynamically.That's what I said: execute immediate doesn't support CLOB!
    But you can concatenate two long's:
    SQL> DECLARE
       l_stmt1   LONG;
       l_stmt2   LONG;
    BEGIN
       l_stmt1 := RPAD ('BEGIN ', 32500, ' ');
       l_stmt2 :=
           RPAD ('  dbms_output.put_line(''Hello World'');', 32500, ' ')
           || 'END;';
       DBMS_OUTPUT.put_line ('Length of statement: '
                             || LENGTH (l_stmt1 || l_stmt2)
       EXECUTE IMMEDIATE (l_stmt1 || l_stmt2);
    END;
    Length of statement: 65004
    Hello World
    PL/SQL procedure successfully completed.So if you strip some extra spaces or try to compact your statement somehow, you might be able use above method.

  • Convert CLOB to VARCHAR2 in Oracle 8i

    Hello all,
    I would like to convert a CLOB column from a table to a VARCHAR2.
    How can I do this?
    I would like that this works in Oracle 8i, 9i and 10g.
    Thank you very much.

    Hello APC,
    I found the problem.
    I have Oracle Reports 6i + patch 17.
    The problem was that I couldn't select a CLOB column and store his value in a CLOB variable.
    I needed to do the conversion DBMS_LOB.SUBSTR in the select statement and store his value in a VARCHAR2 variable.
    Thank you

Maybe you are looking for

  • Auc to Main Asset Line Item wise details

    Hi Expert, i have find and read number of thread regarding details of converted from AUC asset into Main Asset. in sap there is no any standard report where i got the details like AUC asset converted into Main Asset. scenario is , we have create Capi

  • Flash Clipart website not displaying correctly on any company PC's

    We've been having issues displaying any of the graphics from faithclipart.com on our company pc's. PC's are all running the latest version of Flash 10 with IE 8. I can access this site correctly outside of the company. I've disabled firewalls and ant

  • Just need to know

    javascript:smilie(':O') i know this is a problem on the k7n2 delta mobo's But how far out is the temp senor for the cpu. the only reason i ask is when the cpu is running at normal spec " barton 2500" 11 x 166 fsb the temp is 45c at load when the cpu

  • AP-1220 Power Problem

    AP boots fine on ac power but drops power entirely upon connecting ethernet cable.

  • CSS bootup problem

    Hi, I have one CSS11501 without PCMCIA flash disk, I tried to booted it via network, it can normally boot, but after bootup, there are some error message. After login to CSS, it accept very few command only. The attachment is the screen capture file