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.

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

  • 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 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 â 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 view CLOB column in SQLdeveloper

    I'd like to know how to display the value of a CLOB column when in SQLDeveloper. Thanks.

    The data grid's cell has a popup editor (a ... button in the cell) where you can see CLOB contents.
    -Raghu

  • How to convert into columns rows

    Hi all,
    How to convert columns into rows.
    thank you
    regards
    P Prakash

    Whats your DB Version. If its 11g and above you can check out PIVOT and UNPIVOT clause of SELECT statement. Its a new feature of 11g.
    For previous version just search this forum you will get lots of examples.

  • 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 Works doc no longer having Works?

    I have been sent a large Works document. No longer having Works, I am trying to figure out how to convert it into .rtf of some other form that is readable.

    Since you've posted in the AppleWorks forum, by "Works" I assume you mean AppleWorks. There are a few options to get to the contents of that file.
    The easiest & most reliable option other than using AppleWorks or Pages 4 or earlier would be to open the file with LibreOffice. It's a free, open source, Office clone that does a very good job of opening AppleWorks & ClarisWorks files. You can then save them as RTF or Word.
    Second would be to open the file with TextEdit that comes with OS X. You will get a lot of "garbage" formatting text before & after the actual text. That formatting can be many pages long.
    Third would be to look at the options available from Panergy Software. They do have demo software to try.

  • Forms 6.0 how to query clob column with oracle 9.2 DB

    hi every body,
    i made install for oracle 9.2 oracle DB every thing goes ok but when i made query in my form version 6.0 which have CLOB column the form closed automatically without any message?
    and just for know when i run the same form with oracle 8.1.7 DB the form made query normally without any problem.
    i want your help please.
    Message was edited by:
    mshaqalaih

    I know there was a problem in 6i where you would get a crash if your query returned more than {Max Length} characters of the field representing the CLOB column.

  • SQL LOADER: how to load CLOB column using stored function

    Hi,
    I am a newbie of sql loader. Everything seems to be fine until I hit a
    road block - the CLOB column type. I want to load data into the clob
    column using a stored function. I need to do some manipulation on the
    data before it gets saved to that column. But I got this error when I
    run the sql loader.
    SQL*Loader-309: No SQL string allowed as part of "DATA" field
    specification
    DATA is my CLOB type column.
    here is the content of the control file:
    LOAD DATA
    INFILE 'test.csv'
    BADFILE 'test.bad'
    DISCARDFILE 'test.dsc'
    REPLACE
    INTO TABLE test_table
    FIELDS TERMINATED BY ','
    OPTIONALLY ENCLOSED BY '"'
    TRAILING NULLCOLS
    codeid          BOUNDFILLER,
    reason          BOUNDFILLER,
    Checkstamp     "to_date(:CHECKSTAMP, 'mm/dd/yyyy')",
    "DATA"          "GetContent(:codeid, :reason)"
    All references are suggesting to use a file to load data on
    CLOB column but I want to use a function in which it generates
    the content to be saved into the column.
    Any help is greatly appreciated.
    Thanks,
    Baldwin
    MISICompany

    *** Duplicate Post ... Please Ignore ***

  • How to convert single column into single row

    I need to convert single column into single row having n no.of.values in a column. without using case or decode. I need a query to display as below.
    emp_id
    100
    101
    102
    102
    103
    200
    I need output like 100,101,102,103,104.........200.

    I assume you want to convert 200 rows with one column into one row with 200 columns. If so, this is called pivot. If you know number of rows (max possible number of rows) and you are on 11G you can use PIVOT operator (on lower versions GROUP BY + CASE). Otherwise, if row number isn't known, you can use dynamic SQL or assemble select on clent side. Below is example emp_id = 1,2,..5 (to give you idea) and you are on 11G:
    with emp as (
                 select  level emp_id
                   from  dual
                   connect by level <= 5
    select  *
      from  emp
      pivot(
            max(emp_id) for emp_id in (1 emp_id1,2 emp_id2,3 emp_id3,4 emp_id4,5 emp_id5)
       EMP_ID1    EMP_ID2    EMP_ID3    EMP_ID4    EMP_ID5
             1          2          3          4          5
    SQL>
    SY.

  • How to convert  a column   from varchar2 into timestamp(3)

    Hi all,
    I have a date field column with varchar2 as datatype :
    date
    3/13/2011 10:22 AM
    3/13/2011 10:22 AM
    I tried this:
    select to_timestamp(date,'HH24MI') from dual;Iam getting this error:
    ORA-01858: a non-numeric character was found where a numeric was expected
    I want to convert date column to timestamp(3) column

    846773 wrote:
    I want to convert date column to timestamp(3) columnTIMESTAMP is not time column. Look at it as a date with better precision - it supports franctional part of a second. Anyway, use:
    select to_timestamp(date,'MM/DD/YYYY HH:MI AM') from dual;SY.

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

Maybe you are looking for