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.

Similar Messages

  • 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 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

  • 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;

  • 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

  • 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

  • How to convert CLOB to UTF8

    Hi all,
    We have batch job which actually runs on daily basis and produces XML with the Java code.And the XML generated is used for various purposes.
    Recently the job was not executed successfully because of some special characters in XML which falls out of ANSI encoding stantands.
    So we are in a situation to convert the CLOB datatype (input to Java code) to UTF8 encoded XML.
    We are not to able to achieve this .
    Right now the cloB data is converted to ASCII stream,which doesn't create a well formed XML based on UTF8 encoding standards.See below the code
    clob xmlCLOB = (Clob)clobInfo.get("clobfield");
    InputStream is = xmlCLOB.getAsciiStream();
    Any thoughts on how to convert this CLOB to UTF8?
    Regards,
    NaG

    Joan,
    I don't know if this will help with conversion of you BFILE, but at
    http://www.xml.com/lpt/a/2000/04/26/encodings/xmlparser.html
    and at
    http://xmlsoft.org/encoding.html
    there is some information on conversion to UTF8.
    Hope it helps. Let us know.
    Dave

  • 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.

  • How to convert CLOB to varchar2 whose length is more than 4000

    Hi ,
    I have to retrive the CLOB data into varchar2 and spilt those comma seperated values into rows
    but i am getting following error
    " ORA-06502: PL/SQL: numeric or value error: character string buffer too small "
    the proc i used is like following :
    : create table test_clob (grp_id CLOB, id number)
    Create or replace proc test_clob(p_id number )
    Is
    V_clob CLOB;
    V_str varchar2(4000);
    V_main varchar2(30000);
    TYPE t_clob IS REF CURSOR;
    cur_clob t_clob;
    Begin
    Select grp_id
    Into v_str
    From test_clob
    Where id= p_id;
    ---converting column data in rows as I have to return the cursor as output
    V_main:= ' select grp_id from ( WITH t AS
    (SELECT REGEXP_SUBSTR(''' || v_str ||
    ''', ''[^,]+'', 1, LEVEL) txt
    FROM DUAL
    CONNECT BY LEVEL <=
    LENGTH(''' || v_str ||
    LENGTH(REPLACE(''' || v_str ||
    ''', '','')) + 1)
    SELECT REGEXP_SUBSTR(trim(txt), ''[^\,]+'', 1, 1) grp_id
    FROM t )';
    open cur_clob for ' select rtrim(xmlagg(xmlelement(e, grp_id || '','')).extract (''//text()'').getclobval (),'','') grp_id
    from ( '|| v_main||' ) ';
    loop
    fetch cur_clob
    into V_clob;
    exit when cur_clob %notfound;
    end loop;
    insert into test_clob
    values (p_id, v_clob);
    commit;
    End;
    Please help its very urgent

    957624 wrote:
    Hi ,
    I have to retrive the CLOB data into varchar2 and spilt those comma seperated values into rows
    but i am getting following error
    " ORA-06502: PL/SQL: numeric or value error: character string buffer too small "
    the proc i used is like following :
    : create table test_clob (grp_id CLOB, id number)
    Create or replace proc test_clob(p_id number )
    Is
    V_clob CLOB;
    V_str varchar2(4000);
    V_main varchar2(30000);
    TYPE t_clob IS REF CURSOR;
    cur_clob t_clob;
    Begin
    Select grp_id
    Into v_str
    From test_clob
    Where id= p_id;
    ---converting column data in rows as I have to return the cursor as output
    V_main:= ' select grp_id from ( WITH t AS
    (SELECT REGEXP_SUBSTR(''' || v_str ||
    ''', ''[^,]+'', 1, LEVEL) txt
    FROM DUAL
    CONNECT BY LEVEL <=
    LENGTH(''' || v_str ||
    LENGTH(REPLACE(''' || v_str ||
    ''', '','')) + 1)
    SELECT REGEXP_SUBSTR(trim(txt), ''[^\,]+'', 1, 1) grp_id
    FROM t )';
    open cur_clob for ' select rtrim(xmlagg(xmlelement(e, grp_id || '','')).extract (''//text()'').getclobval (),'','') grp_id
    from ( '|| v_main||' ) ';
    loop
    fetch cur_clob
    into V_clob;
    exit when cur_clob %notfound;
    end loop;
    insert into test_clob
    values (p_id, v_clob);
    commit;
    End;
    Please help its very urgentNo, nothing is urgent here and it is very rude to suggest it is, as well as it being a breach of the terms of use for the forums. Urgent issues relate to commercially live systems, and for those you need to raise a support request with Oracle Support. The forums are manned by volunteers with their own jobs to do, so suggesting they drop everything to help you urgently is very rude. Also, other people asking questions would like answers to theirs as soon as possible too, so suggesting your question is more urgent than theirs is also rude to those people. You will find that suggesting your question is urgent will actually prevent people from helping you on the forums as many people will simply choose to ignore you for your rudeness (either that or they'll be rude back)
    Please read {message:id=9360002} to learn how to ask a question properly.
    Now, in answer to your question...
    What is it you are really trying to do?
    If you have comma seperated data, why it is being stored like that in a CLOB? That seems like bad design for storing data.
    If the data is coming from a file, then you could consider using External Tables (or SQL*Loader) to load the comma seperated data in a structured way.
    If you really have data in a clob in comma seperated format, what are you wanting to do with it exactly i.e. what determines where the data should be split?
    Your code isn't clear, but it looks like, on the one hand you are splitting comma seperated data out of a string, and on the other hand you're turning it into XML to get a clob of data back.
    Please be clear by providing some example data and expected output, along with your database version as explained in the FAQ post I linked to above.

  • How to convert clob to varchar2 in an update trigger

    Hi,
    I need to convert a field (clob) to varchar2 in a update trigger, how can I do that?
    regards.

    The maximum amount of data you can store in CLOB column is 4GB.
    You have table TABLE1 having col1 CLOB datatype.You have one more table
    Table_audit_1 without having CLOB datatype column and want to move CLOB
    data into VARCHAR2 column which has maximum length of 4000 and want to
    audit col1 CLOB into VARCHAR2.It seems to me you dont care about the data
    beyond 4000 bytes.
    In 9i SUBSTR, INSTR can be performed without reference to the DBMS_LOB
    package.
    SQL> DROP TABLE mytable
      2  /
    Table dropped.
    SQL> DROP TABLE mytable1
      2  /
    Table dropped.
    SQL> CREATE TABLE mytable
      2  (a   NUMBER,b   CLOB)
      3  /
    Table created.
    SQL> CREATE TABLE mytable1
      2  (c  NUMBER,d   VARCHAR2(4000))
      3  /
    Table created.
    SQL> DECLARE
      2      loc           CLOB;
      3  BEGIN
      4      FOR i IN 1..5000
      5      LOOP
      6        loc:=loc||i;
      7      END LOOP;
      8      INSERT INTO mytable  (a,b) VALUES (1,loc);
      9      INSERT INTO mytable1 (c,d) VALUES (1,SUBSTR(loc,1,4000));
    10      COMMIT;
    11  END;
    12  /
    PL/SQL procedure successfully completed.
    SQL> SET LONG 5000
    SQL> CREATE OR REPLACE TRIGGER mytrigger BEFORE UPDATE ON mytable FOR EACH ROW
      2  BEGIN
      3      UPDATE mytable1
      4         SET d=SUBSTR(:NEW.b,1,4000)
      5       WHERE c=:NEW.a;
      6  END;
      7  /
    Trigger created.
    SQL> DECLARE
      2      loc           CLOB;
      3  BEGIN
      4      FOR i IN 1..1000
      5      LOOP
      6        loc:=loc||'A '||i;
      7      END LOOP;
      8      UPDATE mytable
      9         SET b=loc
    10       WHERE a=1;
    11      COMMIT;
    12  END;
    13  /
    PL/SQL procedure successfully completed.
    SQL> SELECT LENGTH(b) FROM mytable
      2  /
    LENGTH(B)
          4893
    SQL> SELECT LENGTH(d) FROM mytable1
      2  /
    LENGTH(D)
          4000
    SQL> Khurram

  • How to convert clobs to blobs?

    What is the easiest way to go if I want to copy the content of a CLOB to a BLOB(Other than reading the contents of the CLOB out into a buffer and then apply UTL_RAW.CAST_TO_RAW)? How about from blobs to clobs?
    null

    Hi,
    create table myblob(x blob);
    create table myblob1(x clob);
    create or replace procedure blob_to_clob as
    b_lob blob;
    buffer VARCHAR2(32000);
    g_length number;
    begin
    select x into b_lob from myblob;
    g_length := dbms_lob.getlength(b_lob);
    dbms_lob.read(b_lob,g_length,1,buffer);
    insert into myblob1 values(buffer);
    commit;
    end;
    null

  • How to convert CLOB to Char

    Hi all ,
    we have one table Error_log which stores the Error log , one column datatype is CLOB
    but when i use
    select * from error_log ;
    it gives me error so i use to_char function for that CLOB column in select statement
    but now this gives me following error
    ora-22835: buffer too small for clob to char or blob to raw conversion ( actual : 5039 , maximum : 4000)We use toad 7.6
    please help me .

    When i use
    select substr(errstack,1,4000) from error_log
    it gives me error : datatype inconsistentI do not see this on Oracle 10.2.0.1. What version are you using? Show a DESCR on your error_log table so we can confirm the data types of the table's column.
    SQL> col xml format a50
    SQL> select length(xml), substr(xml,1,4000) as xml from xml_files where xml_id = 8928;
    LENGTH(XML_FILE) XML
               22185 <?xml version="1.0" encoding="ISO-8859-1"?><Inventory><Logic
                     alResources><Customer><Status>Updated</S
                     tatus><CustomerID>ACAM97</CustomerID><Cu

  • How to convert XMLTYPE data into CLOB without using getclobval()

    Please tell me how to convert data which is stored in the table in XMLTYPE column to a CLOB.
    When i use getClobVal(), i get an error. So please tell me some other option except getClobVal()

    CREATE OR REPLACE PACKAGE BODY CONVERT_XML_TO_HTML AS
         FUNCTION GENERATE_HTML(TABLE_NAME VARCHAR2, FILE_NAME VARCHAR2, STYLESHEET_QUERY VARCHAR2, WHERE_CLAUSE VARCHAR2, ORDERBY_CLAUSE VARCHAR2) RETURN CLOB IS
         lHTMLOutput XMLType;
         lXSL CLOB;
              lXMLData XMLType;
              FILEID UTL_FILE.FILE_TYPE;
              HTML_RESULT CLOB;
              SQL_QUERY VARCHAR2(300);
              WHERE_QUERY VARCHAR2(200);
              fileDirectory VARCHAR2(100);
              slashPosition NUMBER;
              actual_fileName VARCHAR2(100);
              XML_HTML_REF_CUR_PT XML_HTML_REF_CUR;
              BEGIN
                   IF WHERE_CLAUSE IS NOT NULL AND ORDERBY_CLAUSE IS NOT NULL THEN
                   SQL_QUERY := 'SELECT * FROM ' || TABLE_NAME ||' WHERE ' || WHERE_CLAUSE || ' ORDER BY ' || ORDERBY_CLAUSE;
                        ELSE IF WHERE_CLAUSE IS NOT NULL AND ORDERBY_CLAUSE IS NULL THEN
                             SQL_QUERY := 'SELECT * FROM ' || TABLE_NAME || ' WHERE ' || WHERE_CLAUSE;
                             ELSE IF WHERE_CLAUSE IS NULL AND ORDERBY_CLAUSE IS NOT NULL THEN
                                  SQL_QUERY := 'SELECT * FROM ' || TABLE_NAME || ' ORDER BY ' || ORDERBY_CLAUSE;
                                  ELSE IF WHERE_CLAUSE IS NULL AND ORDERBY_CLAUSE IS NULL THEN
                                  SQL_QUERY := 'SELECT * FROM ' || TABLE_NAME;
                   END IF;
                        END IF;
                             END IF;
                                  END IF;
                   OPEN XML_HTML_REF_CUR_PT FOR SQL_QUERY;
              lXMLData := GENERATE_XML(XML_HTML_REF_CUR_PT);
                   --lXSL := GET_STYLESHEET(STYLESHEET_QUERY);
                                  if(lXMLData is not null) then
                                  dbms_output.put_line('lXMLData pass');
                                  else
                                            dbms_output.put_line('lXMLData fail');
                   end if;
                   lHTMLOutput := lXMLData.transform(XMLType(STYLESHEET_QUERY));
                   --INSERT INTO TEMP_CLOB_TAB2 VALUES(CLOB(lHTMLOutput));
                   if(lHTMLOutput is not null) then
                                  dbms_output.put_line('lHTMLOutput pass');
                                  else
                                            dbms_output.put_line('lHTMLOutput fail');
                   end if;
                   HTML_RESULT := lHTMLOutput.getclobVal();
                   if(HTML_RESULT is not null) then
                                  dbms_output.put_line('HTML_RESULT pass'||HTML_RESULT);
                                  else
                                            dbms_output.put_line('HTML_RESULT fail');
                   end if;
                   -- If the filename has been supplied ...
         IF FILE_NAME IS NOT NULL THEN
    -- locate the final '/' or '\' in the pathname ...
         slashPosition := INSTR(FILE_NAME, '/', -1 );
         IF slashPosition = 0 THEN
         slashPosition := INSTR(FILE_NAME,'\', -1 );
         END IF;
    -- separate the filename from the directory name ...
         fileDirectory := SUBSTR(FILE_NAME, 1,slashPosition - 1 );
         actual_fileName := SUBSTR(FILE_NAME, slashPosition + 1 );
                   END IF;
                        DBMS_OUTPUT.PUT_LINE(fileDirectory||' ' ||actual_fileName);
                   FILEID := UTL_FILE.FOPEN(fileDirectory,actual_fileName, 'W');
                   UTL_FILE.PUT_LINE(FILEID, '<title> hi </title>');
              UTL_FILE.PUT_LINE(FILEID, HTML_RESULT);
                   UTL_FILE.FCLOSE (FILEID);
    DBMS_OUTPUT.PUT_LINE('CLOB SIZE'||DBMS_LOB.GETLENGTH(HTML_RESULT));               
                   RETURN HTML_RESULT;
                   --RETURN lHTMLOutput;
              EXCEPTION
                        WHEN OTHERS
                             THEN DBMS_OUTPUT.PUT_LINE('ERROR!!!!!!!!!!!!');
              END GENERATE_HTML;
         FUNCTION GENERATE_XML(XML_HTML_REF_CUR_PT XML_HTML_REF_CUR) RETURN XMLType IS
              qryCtx DBMS_XMLGEN.ctxHandle;
              result CLOB;
              result1 xmltype;
              BEGIN
                   qryCtx := DBMS_XMLGEN.newContext(XML_HTML_REF_CUR_PT);
                   result := DBMS_XMLGEN.getXML(qryCtx);
                   --dbms_output.put_line(result);
                   result1 := xmltype(result);
                   INSERT INTO temp_clob VALUES(result);
                   if(result1 is not null) then
                                  dbms_output.put_line('pass');
                                  else
                                            dbms_output.put_line('fail');
                   end if;
                        return result1;
                        DBMS_XMLGEN.closeContext(qryCtx);
         END GENERATE_XML;     
    END CONVERT_XML_TO_HTML;
    This is the code which i am using to generate the XML and subsequently to generate the HTML output out of that using a XSL stylesheet.
    The error is Numeric or value error..

  • How to convert a CLOB to BLOB

    Hi,
    Can any one tell me how to convert a CLOB into BLOB? In Oracle 10g there is a function which is converttoblob(). But in Oracle 9i there is no function as such. If i am using Hextoraw() function still then its giving some pointer error. please let me know the solution.

    FUNCTION c2b( c IN CLOB ) RETURN BLOB
    -- typecasts CLOB to BLOB (binary conversion)
    IS
    pos PLS_INTEGER := 1;
    buffer RAW( 32767 );
    res BLOB;
    lob_len PLS_INTEGER := DBMS_LOB.getLength( c );
    BEGIN
    DBMS_LOB.createTemporary( res, TRUE );
    DBMS_LOB.OPEN( res, DBMS_LOB.LOB_ReadWrite );
    LOOP
    buffer := UTL_RAW.cast_to_raw( DBMS_LOB.SUBSTR( c, 16000, pos ) );
    IF UTL_RAW.LENGTH( buffer ) > 0 THEN
    DBMS_LOB.writeAppend( res, UTL_RAW.LENGTH( buffer ), buffer );
    END IF;
    pos := pos + 16000;
    EXIT WHEN pos > lob_len;
    END LOOP;
    RETURN res; -- res is OPEN here
    END c2b;

  • How to Convert Report into Excel Sheet when Sending Mail.

    Dear Friends,
    i want to send mail to HOD of Product with an Excel Sheet .
    i want to send Pending Issue details to HOD in Excel Sheet attachment .
    here i have pending issue report now i need to send it in Excel Sheet attachment .
    i have table where i have manage Product ID and HOD OF PRODUCT.
    CREATE TABLE  "MAP_USER_PRODUCT_DTL"
       (     "ID" NUMBER NOT NULL ENABLE,
         "PRODUCT_ID"NUMBER,
         "USER_ID" VARCHAR2(5) NOT NULL ENABLE,
         "HOD_PROD" VARCHAR2(100)========================================Value is Y OR N IF HOD then Y else N
         CONSTRAINT "MAP_USER_PRODUCT_DTL_PK" PRIMARY KEY ("ID") ENABLE
    /i have one more table where all complete issue detail insert.
    CREATE TABLE  "CRM_ISSUE_PROBLEM"
       (     "ID" NUMBER,
         "SUBJECT" VARCHAR2(255) NOT NULL ENABLE,
         "CLIENT_ID" NUMBER,
         "ASSIGNED_TO_ID" VARCHAR2(100),
         "ASSIGNED_ON" DATE,
         "DESCRIPTION" VARCHAR2(4000),
         "PRODUCT_ID" NUMBER NOT NULL ENABLE,
         "STATUS_ID" NUMBER NOT NULL ENABLE,
          CONSTRAINT "CRM_ISSUE_PROBLEM_PK" PRIMARY KEY ("ID") ENABLE
    Here STATUS_ID is Like Pending ISsue,Open Issue and Close Issue .i want to send mail to HOD with Pending Issue Report convert into Excel Sheet and send to HOD?
    How can i do this.
    Thanks
    Edited by: Vedant on Oct 12, 2011 12:36 AM
    Edited by: Vedant on Oct 12, 2011 2:22 AM

    Hello Vedant,
    Would it suffice if you send a CSV file?
    If yes, then see following code.. run the code under APEX > Home > SQL Workshop > SQL Commands
    DECLARE
            ln_id NUMBER;
            lc_clob CLOB;
         lb_blob BLOB;
         li_in PLS_INTEGER := 1;
         li_out PLS_INTEGER := 1;
         li_lang PLS_INTEGER := 0;
         li_warning PLS_INTEGER := 0;
         lv_mail_rcpts VARCHAR2(2000) := '[email protected]';
         lv_mail_from VARCHAR2(100) := '[email protected]';     
           lv_clmn_separator VARCHAR2(1) := ',';
    BEGIN
         -- Build file content as CLOB
      -- Replace with your query
         FOR i IN (select object_id A, object_name B, object_type C, status D, temporary E, generated F, secondary G,namespace H from user_objects where rownum < 10)               
         LOOP
        IF lc_clob IS NULL THEN
          lc_clob := i.A||lv_clmn_separator||i.B||lv_clmn_separator||i.C||lv_clmn_separator||i.D||lv_clmn_separator||i.E||lv_clmn_separator||i.F||lv_clmn_separator||i.G||lv_clmn_separator||i.H;
        ELSE
          lc_clob := lc_clob||CHR(10)||i.A||lv_clmn_separator||i.B||lv_clmn_separator||i.C||lv_clmn_separator||i.D||lv_clmn_separator||i.E||lv_clmn_separator||i.F||lv_clmn_separator||i.G||lv_clmn_separator||i.H;
        END IF;
         END LOOP; 
         -- Convert CLOB to BLOB
         DBMS_LOB.CREATETEMPORARY(lb_blob,TRUE);
         DBMS_LOB.convertToBlob(lb_blob,lc_clob,DBMS_LOB.LOBMAXSIZE,li_in,li_out,DBMS_LOB.DEFAULT_CSID,li_lang,li_warning);
         -- Send mail
         ln_id:= APEX_MAIL.SEND(
           p_to        => lv_mail_rcpts,
                 p_from      => lv_mail_from,
                 p_subj      => 'Subject Goes here',
                 p_body      => 'Body goes here'
           -- add CSV file as attachment
         APEX_MAIL.ADD_ATTACHMENT
           p_mail_id   => ln_id,
           p_attachment => lb_blob,
           p_filename   => 'filename.csv',
           p_mime_type  => 'application/csv'
      -- push mail queue
      APEX_MAIL.PUSH_QUEUE;
         -- empty temporary space
         DBMS_LOB.FREETEMPORARY ( lob_loc =>  lb_blob);       
         COMMIT;
    END;Regards,
    Hari

Maybe you are looking for

  • Mac Yosemite 10.10.2 -- System Pref. Java pane/ctrl-panel, Update-tab-function no-longer works, after updting to Java 8v40

    Under the Mac Yosemite 10.10.2 O.S. -- the System Preferences: Java pane/ctrl-panel: Update-tab-function no-longer works, after updting to Java 8v40 JRE & SDK -- says that the internet connection is not valid !

  • Regarding Performance It is Urgent.

    hi      I have one statement    move-corresponding gt_bkpf to post_tab. In gt_bkpf  Internal Table 10 fields are there. Post_tab is another Internal Table. In performance issue you need to use ASSIGN instead of move-corresponding. How can i do it. Pl

  • [SOLVED]Cannot copy/cut/paste files in Konqueror

    Hi all, I am using KDE4.1.2 (official version). My konqueror cannot copy/cut/paste files in 'file manager' mode, the copy/cut/paste items in the right click menu are always faded out, and C-x/C-c/C-v hotkeys do not work either. However, it can read/w

  • Trying to monitor my sql servers in OEM Grid Control

    Hello, I have Oracle 10g OEM and I want to start monitoring my sql server databases. I've got the plug-in all setup but when it displays under my "Databases" it shows and status "down". My sql server host is running, listener running, and database is

  • What do i have to download?

    so i have a new ipod video and arnt i supposed to download some main program to my computer so i can actually use my ipod? i cant find it on the support place... W3507 desktop pc   Windows XP