Convert UTF8 clob charset

Thanks for your advice.
Actually NLS support may not apply to my case because I need to specify different charset when I need the CLOB UTF8 data from my database. Maybe this time I need Big5, next time I need GBK. The thing is, I know there is a function to convert varchar2 from UTF8 to different charset.
Question is: can I convert CLOB as well?
Thanks for any advice!

There are no SQL convert functions to handle CLOB conversion in Oracle8i . In 9i all SQL functions for VARCHAR2 will work with CLOBs too.
Why do you need to have do the conversion explicitly, if you set your client NLS_LANG character set to ZHT16BIG5 or ZHT16GBK , they these CLOBs should be converted to the client Character set automatically.

Similar Messages

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

  • Trying to convert a CLOB to an XMLTYPE

    I'm trying to insert a xm ldocument stored in a CLOB into a XMLTYPE column registered to a schema.
    I'm trying so use the function below to convert the CLOB to an XMLTYPEbut i keep getting a ORA-06553 Error: wrong number or arguments. Am i using the xmltype constructor properly?
    create or replace function to_xmltype (clobcol CLOB)
    return xmltype as
    begin
    return xmltype(clobcol,'http://localhost:8080/source/schemas/poSource/xsd/mySchema.xsd');
    end;
    insert into xml_table (xmldata) values (select to_xmltype(ct.clob_data) from clob_table ct );
    Thanks for the help

    Looks fine to me except that you should omit the values clause:
    insert into xml_table (xmldata) select to_xmltype(ct.clob_data) from clob_table ct ;

  • Convert UTF8 to WE8ISO8859P1 or WE8ISO8859P15

    Hi!
    If got the following situation:
    I've got a database with the character set WE8ISO8859P1.
    I've got a second database with UTF8.
    I think all databases are 10.2.xx
    There is a pl/sql interface on the WE8ISO8859P1 Database which reads data from the UTF8 database via database link.
    But after inserting UTF8-data into the WE8ISO8859P1 database, the are not converted correctly automaticaly.
    How can i convert UTF8-data within my WE8ISO8859P1 database to WE8ISO8859P1-data?
    Is there a standard function within the WE8ISO8859P1 database?
    e.g. Select standard_convert_func(my_col, 'UTF8', 'WE8ISO8859P1') from myTable@db_link
    Or is the better way to convert this utf8-data to WE8ISO8859P1 within the UTF-8 database?
    insert into my_interface_tabele(my_col) select standard_convert_func(my_col, 'UTF8', 'WE8ISO8859P1') from my_utf8_base_tabel;
    Thank you for your help!
    Best regards,
    Thomas

    Hi!
    Within my ISO-DB i receive the following results in SQL*Plus:
    SQL> select convert(DN_DIENSTTITEL, 'WE8ISO8859P1', 'UTF8')
    2 from dn_stammtest@lsal_n_pep_test_link;
    CONVERT(DN_DIENSTTITEL,'WE8ISO8859P1','UTF8')
    A K B A R I A N `ag6 ¿ N a t a l
    SQL> ed
    Datei afiedt.buf wurde geschrieben
    1 select dump(DN_DIENSTTITEL)
    2* from dn_stammtest@lsal_n_pep_test_link
    SQL> r
    1 select dump(DN_DIENSTTITEL)
    2* from dn_stammtest@lsal_n_pep_test_link
    DUMP(DN_DIENSTTITEL)
    Typ=1 Len=40: 0,65,0,75,0,66,0,65,0,82,0,73,0,65,0,78,0,32,1,96,1,97,1,103,4,54,32,172,0,32,0,78,0,9
    I will contact the DB-Admin to do this select within the UTF8 DB.
    Best regards.
    Thomas

  • Converting a CLOB toBLOB

    Hi
    Is it possible to convert a CLOB data to a BLOB data?
    Thanks in advance
    bye

    or vice versa?

  • Encoding problem with convert and CLOB involving UTF8 and EBCDIC

    Hi,
    I have a task that requires me to call a procedure with a CLOB argument containing a string encoded in EBCDIC. This did not go well so I started narrowing down the problem. Here is some SQL to illustrate it:
    SQL> select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    PL/SQL Release 10.2.0.4.0 - Production
    CORE 10.2.0.4.0 Production
    TNS for Solaris: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - Production
    SQL> select value from v$nls_parameters where parameter = 'NLS_CHARACTERSET';
    VALUE
    AL32UTF8
    SQL> select convert(convert('abc', 'WE8EBCDIC500'), 'AL32UTF8', 'WE8EBCDIC500')
    output from dual;
    OUT
    abc
    SQL> select convert(to_char(to_clob(convert('abc', 'WE8EBCDIC500'))), 'AL32UTF8', 'WE8EBCDIC500') output from dual;
    OUTPUT
    ╒╫¿╒╫¿╒╫¿
    So converting to and from EBCDIC works fine when using varchar2, but (if I am reading this right) fails when involving CLOB conversion.
    My question then is: Can anyone demonstrate how to put correct EBCDIC into a CLOB and maybe even explain why the examples do what they do.

    in order to successfully work with xmldb it is recommended that you use 9.2.0.4
    and above. Its seems to have lower version.
    Okay now related to the problem , if your data that you want to send to the attributes are not greater than 32767, then you can use the pl/sql varchar2 datatype to hold the data rather then CLOB and overcome this problem.
    here is the sample. use function with below pl/sql to return the desired output.
    SQL> declare
      2   l_clob     CLOB := 'Hello';
      3   l_output   CLOB;
      4  begin
      5    select  xmlelement("test", xmlattributes(l_clob AS "a")).getclobval()
      6      into l_output from dual;
      7  end;
      8  /
      select  xmlelement("test", xmlattributes(l_clob AS "a")).getclobval()
    ERROR at line 5:
    ORA-06550: line 5, column 44:
    PL/SQL: ORA-00932: inconsistent datatypes: expected - got CLOB
    ORA-06550: line 5, column 3:
    PL/SQL: SQL Statement ignored
    SQL> declare
      2   l_vchar     varchar2(32767) := 'Hello';
      3   l_output   CLOB;
      4  begin
      5    select  xmlelement("test", xmlattributes(l_vchar AS "a")).getclobval()
      6      into l_output from dual;
      7    dbms_output.put_line(l_output);
      8  end;
      9  /
    <test a="Hello"></test>
    PL/SQL procedure successfully completed.

  • CLOB / Charset / Java / Unix Issue

    Hi,
    I'm encountering the following problem.
    I'm working on a 3-tiers architecture with an Oracle Database (8.1.7)
    a Weblogic application server 6.1 SP4 and a Web server under Aix 4.3
    (all 3 are under AIX 4.3 on the same platform).
    My application has a web interface that allows users to upload files
    to the server from their PC clients and a webbrowser, that insert each
    file into a oracle Clob (via Java Code) and that call a stored
    procedure (with java code again) to extract this clob to a file
    (UTL_file package), then, the extracted file is processed line by line
    and information inserted in others tables.
    The issue is that some characters (acute, grave accent ....etc)
    appears as question marks in the database or that some date from the
    file can't be processed because they are structured as DD/MM/YYYY
    (french notation, but that normal I'm from france).
    I first thougt of an NLS_LANG problem but on the weblogic server it is
    set to french_france.WE88859P15 that seems to be right and the same
    the database configuration.
    I then tried to performs some conversion when the clob data were
    extracted to file (from WE88859P15 TO CP152 or vice-versa) with the
    oracle convert function but it seems that it doesn't work.
    An other but coherent symptoms is that the extracted files (from the
    clob columns) seems not to be fine (accent are not recognized).
    This is the java code used to load file to clob (on the weblogic
    server side)
    con = dbHandle.getAdminConnection();
    con.setAutoCommit(false);
    /// NEW IMPORT
    // int taskId = DBTools.getOraSeqValue("vtr.VTR_SEQ_LOG_IMPORT",
    DBTools.NEXTVAL,con);
    int taskId = DBTools.getOraSeqValue(SqlQueryDefinition.seqLogImport.toString(),
    DBTools.NEXTVAL,con);
    Debug.out.println("taskId " + taskId);
    // String cmd = "insert into vtr.vtr_log_import
    (cod_task,DTE_DEBUT,lob_imp,lob_rej,lob_log, txt_nom_fic_orig,
    txt_utilisateur) " +
    // "values ("+ taskId
    +",sysdate,empty_clob(),empty_clob(),empty_clob(), '"+file+"','"+
    ((UserBean)request.getSession().getAttribute("userbean")).getIdentifier()+"')";
    // stmt = con.createStatement();
    // stmt.executeQuery(cmd);
    // stmt.close();
    pstmt = con.prepareStatement(SqlQueryDefinition.initLigneImport.toString());
    pstmt.setInt(1,taskId);
    pstmt.setString(2,file);
    pstmt.setString(3,((UserBean)request.getSession().getAttribute("userbean")).getIdentifier());
    pstmt.executeQuery();
    pstmt.close();
    con.commit();
    // Writing CLOB
    // cmd = "SELECT cod_task,lob_imp,lob_rej,lob_log FROM
    vtr.vtr_log_import WHERE cod_task="+ taskId +" for update";
    // stmt = con.createStatement();
    // rset = stmt.executeQuery(cmd);
    pstmt = con.prepareStatement(SqlQueryDefinition.setBlobImport.toString());
    pstmt.setInt(1,taskId);
    rset = pstmt.executeQuery();
    rset.next();
    File csvFile = new File(localFile);
    System.out.println("csvFile length = " + csvFile.length());
    File unixFile = new File(localFile+".ux");
    Tools.dos2Unix(csvFile, unixFile);
    FileInputStream instream = new FileInputStream(unixFile);
    // support Weblogic
    clob = ClobComponent.factory(DBUtil.getInstance().isWebLogicPlatform());
    clob.setClob(rset,2);
    outstream = clob.getAsciiOutputStream();
    size = clob.getBufferSize();
    byte[] buffer = new byte[size];
    int length = -1;
    while ((length = instream.read(buffer)) != -1)
    outstream.write(buffer, 0, length);
    instream.close();
    outstream.close();
    rset.close();
    // stmt.close();
    pstmt.close();
    rset=null;
    // stmt = null;
    pstmt=null;
    con.commit();
    // IMPORT
    cs = con.prepareCall(SqlQueryDefinition.importStoredProc.toString());
    index = 1;
    cs.setString(index++, fullPath); // 1
    cs.setString(index++,
    ((UserBean)request.getSession().getAttribute("userbean")).getIdentifier());
    // 2
    cs.registerOutParameter(index++,java.sql.Types.VARCHAR); // 3
    cs.registerOutParameter(index++,java.sql.Types.VARCHAR); // 4
    cs.registerOutParameter(index++,java.sql.Types.NUMERIC); // 5
    cs.setInt(index++, taskId); // 6
    cs.executeQuery();
    String fichier1 = cs.getString(3);
    String fichier2 = cs.getString(4);
    int returnCode = cs.getInt(5);
    System.out.println("returnCode/fichier1/2 : " + returnCode + " & "
    + fichier1 + " & " + fichier2);
    cs.close();
    con.commit();
    This is the PL/SQL code used to unload clob to dile (on the oracle
    side)
    PROCEDURE writeToFile (id NUMBER, a_fichier VARCHAR2)
    IS
    result CLOB;
    cvl_tmp VARCHAR2 (32000);
    nvl_amount NUMBER := 250;
    nvl_pos NUMBER := 1;
    nvl_clob_length NUMBER;
    instr_pos NUMBER;
    file_handle UTL_FILE.file_type;
    BEGIN
    file_handle := UTL_FILE.FOPEN(
    substr(a_fichier, 1, instr(a_fichier, file_separator, -1,
    1)-1), -- dir
    substr(a_fichier, instr(a_fichier, file_separator, -1, 1)+1),
    -- file
    'W');
    select lob_imp
    INTO result
    from vtr_log_import
    where cod_task = id;
    --write clob to file
    nvl_clob_length := DBMS_LOB.getlength (result);
    cvl_tmp := NULL;
    nvl_amount := 250;
    nvl_pos := 1;
    LOOP
    instr_pos :=
    DBMS_LOB.INSTR (result, CHR (10), nvl_pos, 1) -
    nvl_pos;
    --DBMS_OUTPUT.PUT_LINE(nvl_pos||': Of length : '||instr_pos);
    IF nvl_pos + instr_pos > nvl_clob_length
    THEN
    instr_pos := nvl_clob_length - nvl_pos;
    DBMS_LOB.READ (
    lob_loc=> result,
    amount=> instr_pos,
    offset=> nvl_pos,
    buffer=> cvl_tmp
    EXIT;
    END IF;
    DBMS_LOB.READ (
    lob_loc=> result,
    amount=> instr_pos,
    offset=> nvl_pos,
    buffer=> cvl_tmp
    -- DBMS_OUTPUT.PUT_LINE(cvL_tmp);
    cvl_tmp := CONVERT(cvl_tmp, 'WE8MSWIN1252', 'WE8ISO8859P15');
    UTL_FILE.put_line (file_handle, cvl_tmp);
    nvl_pos := nvl_pos
    + instr_pos
    + 1;
    IF nvl_pos > nvl_clob_length
    THEN
    EXIT;
    END IF;
    END LOOP;
    UTL_FILE.fclose (file_handle);
    END writeToFile;
    I'm using the oracle thin driver but it's not set in classpath maybe a
    problem with that ?
    <JDBCConnectionPool DriverName="oracle.jdbc.driver.OracleDriver"
    InitialCapacity="1" MaxCapacity="100" Name="oracleUserPool"
    Password="XXXXXXX
    Properties="user=vtr_usr;dll=ocijdbc8;protocol=thin"
    Targets="myserver" TestConnectionsOnRelease="true"
    TestConnectionsOnReserve="true" TestTableName="dual"
    URL="jdbc:oracle:thin:@localhost:1521:ssr"/>
    Maybe a problem with the properties of weblogic.codeset (I don"t set
    it) ?
    Many thanks in advance, I have no idea even if I suspect the java
    store to file or the UTL_file extration to file steps to be in cause !
    Run-O

    Run-O wrote:
    Hi,
    I'm encountering the following problem.Hi. The first thing I'd do to narrow the search is to see if my Java code
    worked in a standalone program, without weblogic in the picture. Once
    you get Oracle's JDBC driver to work with Oracle's DBMS, it shouldn't
    be hard to get the same stuff to work inside weblogic, or find out why it
    doesn't.
    Joe
    >
    >
    I'm working on a 3-tiers architecture with an Oracle Database (8.1.7)
    a Weblogic application server 6.1 SP4 and a Web server under Aix 4.3
    (all 3 are under AIX 4.3 on the same platform).
    My application has a web interface that allows users to upload files
    to the server from their PC clients and a webbrowser, that insert each
    file into a oracle Clob (via Java Code) and that call a stored
    procedure (with java code again) to extract this clob to a file
    (UTL_file package), then, the extracted file is processed line by line
    and information inserted in others tables.
    The issue is that some characters (acute, grave accent ....etc)
    appears as question marks in the database or that some date from the
    file can't be processed because they are structured as DD/MM/YYYY
    (french notation, but that normal I'm from france).
    I first thougt of an NLS_LANG problem but on the weblogic server it is
    set to french_france.WE88859P15 that seems to be right and the same
    the database configuration.
    I then tried to performs some conversion when the clob data were
    extracted to file (from WE88859P15 TO CP152 or vice-versa) with the
    oracle convert function but it seems that it doesn't work.
    An other but coherent symptoms is that the extracted files (from the
    clob columns) seems not to be fine (accent are not recognized).
    This is the java code used to load file to clob (on the weblogic
    server side)
    con = dbHandle.getAdminConnection();
    con.setAutoCommit(false);
    /// NEW IMPORT
    // int taskId = DBTools.getOraSeqValue("vtr.VTR_SEQ_LOG_IMPORT",
    DBTools.NEXTVAL,con);
    int taskId = DBTools.getOraSeqValue(SqlQueryDefinition.seqLogImport.toString(),
    DBTools.NEXTVAL,con);
    Debug.out.println("taskId " + taskId);
    // String cmd = "insert into vtr.vtr_log_import
    (cod_task,DTE_DEBUT,lob_imp,lob_rej,lob_log, txt_nom_fic_orig,
    txt_utilisateur) " +
    // "values ("+ taskId
    +",sysdate,empty_clob(),empty_clob(),empty_clob(), '"+file+"','"+
    ((UserBean)request.getSession().getAttribute("userbean")).getIdentifier()+"')";
    // stmt = con.createStatement();
    // stmt.executeQuery(cmd);
    // stmt.close();
    pstmt = con.prepareStatement(SqlQueryDefinition.initLigneImport.toString());
    pstmt.setInt(1,taskId);
    pstmt.setString(2,file);
    pstmt.setString(3,((UserBean)request.getSession().getAttribute("userbean")).getIdentifier());
    pstmt.executeQuery();
    pstmt.close();
    con.commit();
    // Writing CLOB
    // cmd = "SELECT cod_task,lob_imp,lob_rej,lob_log FROM
    vtr.vtr_log_import WHERE cod_task="+ taskId +" for update";
    // stmt = con.createStatement();
    // rset = stmt.executeQuery(cmd);
    pstmt = con.prepareStatement(SqlQueryDefinition.setBlobImport.toString());
    pstmt.setInt(1,taskId);
    rset = pstmt.executeQuery();
    rset.next();
    File csvFile = new File(localFile);
    System.out.println("csvFile length = " + csvFile.length());
    File unixFile = new File(localFile+".ux");
    Tools.dos2Unix(csvFile, unixFile);
    FileInputStream instream = new FileInputStream(unixFile);
    // support Weblogic
    clob = ClobComponent.factory(DBUtil.getInstance().isWebLogicPlatform());
    clob.setClob(rset,2);
    outstream = clob.getAsciiOutputStream();
    size = clob.getBufferSize();
    byte[] buffer = new byte[size];
    int length = -1;
    while ((length = instream.read(buffer)) != -1)
    outstream.write(buffer, 0, length);
    instream.close();
    outstream.close();
    rset.close();
    // stmt.close();
    pstmt.close();
    rset=null;
    // stmt = null;
    pstmt=null;
    con.commit();
    // IMPORT
    cs = con.prepareCall(SqlQueryDefinition.importStoredProc.toString());
    index = 1;
    cs.setString(index++, fullPath); // 1
    cs.setString(index++,
    ((UserBean)request.getSession().getAttribute("userbean")).getIdentifier());
    // 2
    cs.registerOutParameter(index++,java.sql.Types.VARCHAR); // 3
    cs.registerOutParameter(index++,java.sql.Types.VARCHAR); // 4
    cs.registerOutParameter(index++,java.sql.Types.NUMERIC); // 5
    cs.setInt(index++, taskId); // 6
    cs.executeQuery();
    String fichier1 = cs.getString(3);
    String fichier2 = cs.getString(4);
    int returnCode = cs.getInt(5);
    System.out.println("returnCode/fichier1/2 : " + returnCode + " & "
    + fichier1 + " & " + fichier2);
    cs.close();
    con.commit();
    This is the PL/SQL code used to unload clob to dile (on the oracle
    side)
    PROCEDURE writeToFile (id NUMBER, a_fichier VARCHAR2)
    IS
    result CLOB;
    cvl_tmp VARCHAR2 (32000);
    nvl_amount NUMBER := 250;
    nvl_pos NUMBER := 1;
    nvl_clob_length NUMBER;
    instr_pos NUMBER;
    file_handle UTL_FILE.file_type;
    BEGIN
    file_handle := UTL_FILE.FOPEN(
    substr(a_fichier, 1, instr(a_fichier, file_separator, -1,
    1)-1), -- dir
    substr(a_fichier, instr(a_fichier, file_separator, -1, 1)+1),
    -- file
    'W');
    select lob_imp
    INTO result
    from vtr_log_import
    where cod_task = id;
    --write clob to file
    nvl_clob_length := DBMS_LOB.getlength (result);
    cvl_tmp := NULL;
    nvl_amount := 250;
    nvl_pos := 1;
    LOOP
    instr_pos :=
    DBMS_LOB.INSTR (result, CHR (10), nvl_pos, 1) -
    nvl_pos;
    --DBMS_OUTPUT.PUT_LINE(nvl_pos||': Of length : '||instr_pos);
    IF nvl_pos + instr_pos > nvl_clob_length
    THEN
    instr_pos := nvl_clob_length - nvl_pos;
    DBMS_LOB.READ (
    lob_loc=> result,
    amount=> instr_pos,
    offset=> nvl_pos,
    buffer=> cvl_tmp
    EXIT;
    END IF;
    DBMS_LOB.READ (
    lob_loc=> result,
    amount=> instr_pos,
    offset=> nvl_pos,
    buffer=> cvl_tmp
    -- DBMS_OUTPUT.PUT_LINE(cvL_tmp);
    cvl_tmp := CONVERT(cvl_tmp, 'WE8MSWIN1252', 'WE8ISO8859P15');
    UTL_FILE.put_line (file_handle, cvl_tmp);
    nvl_pos := nvl_pos
    + instr_pos
    + 1;
    IF nvl_pos > nvl_clob_length
    THEN
    EXIT;
    END IF;
    END LOOP;
    UTL_FILE.fclose (file_handle);
    END writeToFile;
    I'm using the oracle thin driver but it's not set in classpath maybe a
    problem with that ?
    <JDBCConnectionPool DriverName="oracle.jdbc.driver.OracleDriver"
    InitialCapacity="1" MaxCapacity="100" Name="oracleUserPool"
    Password="XXXXXXX
    Properties="user=vtr_usr;dll=ocijdbc8;protocol=thin"
    Targets="myserver" TestConnectionsOnRelease="true"
    TestConnectionsOnReserve="true" TestTableName="dual"
    URL="jdbc:oracle:thin:@localhost:1521:ssr"/>
    Maybe a problem with the properties of weblogic.codeset (I don"t set
    it) ?
    Many thanks in advance, I have no idea even if I suspect the java
    store to file or the UTL_file extration to file steps to be in cause !
    Run-O

  • Converting UTF8 to US7ASCII

    Hello,
    We have a database which is 9i and has a NLS_CHARACTERSET set to US7ASCII.
    We created a new database (version 10g 10.2.0.2.0) on a new server which has a NLS_CHARACTERSET set to UTF 8. When we exported the database from the 9i database to 10g database, obviously because of the NLS_CHARACTERSET there was an issue of data corruption (Columns width increasing by 3 times, understandable). Is there a way to convert the UTF8 character set on the 10g database to US7ASCII character set, and then re-importing and exporting the 9i database to 10g database. I know we can convert a subset to superset. I want to find out if there is a way to convert a superset to a subset.
    Or do I have to re-create the whole database again.
    Thanks,
    Kalyan

    You shouldn't have problem migrate a US7ASCII to UTF8. UTF8 is superset of US7ASCII.
    The problem you are facing is when your schema has column defined as CHAR(20) for example, a single byte character becomes a two-byte character in UTF8, you now have Data Truncation issue. Same problem can also happens in varchar type.
    You can't change from superset to subset for obvious reason but you can convert your 9i from US7ASCII to UTF8 if you like.
    Also run this character set scanner before you make conversion.
    http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96529/ch11.htm#1005049

  • Query Column List convert to CLOB

    Hi,
    we need to print the data by using UTL_FILE from the dynamically constructing sql query with pivot column (It is having more than 1000 column).
    But this query contains 1008 columns but it throwing error maxmimum number of columns in a table or views 1000.
    Query
    Select col1,col2,col3,clo4,col5,col6,col7,col8 ,Pivot columns 1 to 1000 from tab1
    Each and every column data having more than 3500.
    Please share your idea ?
    1.is it possoble to concatenate all the columns and write into file using utl_file.
    2.How to convert the rows as clob column
    3.Each and every row should contains more than 32767.
    Regards,
    Sudhakar P.

    Sudhakar P wrote:
    Hi,
    we need to print the data by using UTL_FILE from the dynamically constructing sql query with pivot column (It is having more than 1000 column).
    But this query contains 1008 columns but it throwing error maxmimum number of columns in a table or views 1000.Can't overcome Oracle's internal limits.
    Each and every column data having more than 3500.More than 3500 what?
    1.is it possoble to concatenate all the columns and write into file using utl_file.Yes.
    2.How to convert the rows as clob columnUse built in LOB functionality, such as provided in the DBMS_LOB package for example.
    3.Each and every row should contains more than 32767.You would have to use CLOB's to store more than 4000 characters in SQL. 32767 is the limit in PL/SQL for VARCHAR2.
    If it's dynamic, then you're going to have to pretty much use the DBMS_SQL package to construct things (11g allows the use of CLOB with EXECUTE IMMEDIATE for dynamic statements but it's still not ideal to get the data back if you don't know the output structure).
    Here's an example from my standard library for writing out dynamic SQL output to a CSV file, which would probably be a good starting point...
    As sys user:
    CREATE OR REPLACE DIRECTORY TEST_DIR AS '\tmp\myfiles'
    GRANT READ, WRITE ON DIRECTORY TEST_DIR TO myuser
    /As myuser:
    CREATE OR REPLACE PROCEDURE run_query(p_sql IN VARCHAR2
                                         ,p_dir IN VARCHAR2
                                         ,p_header_file IN VARCHAR2
                                         ,p_data_file IN VARCHAR2 := NULL) IS
      v_finaltxt  VARCHAR2(4000);
      v_v_val     VARCHAR2(4000);
      v_n_val     NUMBER;
      v_d_val     DATE;
      v_ret       NUMBER;
      c           NUMBER;
      d           NUMBER;
      col_cnt     INTEGER;
      f           BOOLEAN;
      rec_tab     DBMS_SQL.DESC_TAB;
      col_num     NUMBER;
      v_fh        UTL_FILE.FILE_TYPE;
      v_samefile  BOOLEAN := (NVL(p_data_file,p_header_file) = p_header_file);
    BEGIN
      c := DBMS_SQL.OPEN_CURSOR;
      DBMS_SQL.PARSE(c, p_sql, DBMS_SQL.NATIVE);
      d := DBMS_SQL.EXECUTE(c);
      DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
      FOR j in 1..col_cnt
      LOOP
        CASE rec_tab(j).col_type
          WHEN 1 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
          WHEN 2 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_n_val);
          WHEN 12 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_d_val);
        ELSE
          DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
        END CASE;
      END LOOP;
      -- This part outputs the HEADER
      v_fh := UTL_FILE.FOPEN(upper(p_dir),p_header_file,'w',32767);
      FOR j in 1..col_cnt
      LOOP
        v_finaltxt := ltrim(v_finaltxt||','||lower(rec_tab(j).col_name),',');
      END LOOP;
      --  DBMS_OUTPUT.PUT_LINE(v_finaltxt);
      UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
      IF NOT v_samefile THEN
        UTL_FILE.FCLOSE(v_fh);
      END IF;
      -- This part outputs the DATA
      IF NOT v_samefile THEN
        v_fh := UTL_FILE.FOPEN(upper(p_dir),p_data_file,'w',32767);
      END IF;
      LOOP
        v_ret := DBMS_SQL.FETCH_ROWS(c);
        EXIT WHEN v_ret = 0;
        v_finaltxt := NULL;
        FOR j in 1..col_cnt
        LOOP
          CASE rec_tab(j).col_type
            WHEN 1 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
                        v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
            WHEN 2 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_n_val);
                        v_finaltxt := ltrim(v_finaltxt||','||v_n_val,',');
            WHEN 12 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_d_val);
                        v_finaltxt := ltrim(v_finaltxt||','||to_char(v_d_val,'DD/MM/YYYY HH24:MI:SS'),',');
          ELSE
            v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
          END CASE;
        END LOOP;
      --  DBMS_OUTPUT.PUT_LINE(v_finaltxt);
        UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
      END LOOP;
      UTL_FILE.FCLOSE(v_fh);
      DBMS_SQL.CLOSE_CURSOR(c);
    END;This allows for the header row and the data to be written to seperate files if required.
    e.g.
    SQL> exec run_query('select * from emp','TEST_DIR','output.txt');
    PL/SQL procedure successfully completed.Output.txt file contains:
    empno,ename,job,mgr,hiredate,sal,comm,deptno
    7369,"SMITH","CLERK",7902,17/12/1980 00:00:00,800,,20
    7499,"ALLEN","SALESMAN",7698,20/02/1981 00:00:00,1600,300,30
    7521,"WARD","SALESMAN",7698,22/02/1981 00:00:00,1250,500,30
    7566,"JONES","MANAGER",7839,02/04/1981 00:00:00,2975,,20
    7654,"MARTIN","SALESMAN",7698,28/09/1981 00:00:00,1250,1400,30
    7698,"BLAKE","MANAGER",7839,01/05/1981 00:00:00,2850,,30
    7782,"CLARK","MANAGER",7839,09/06/1981 00:00:00,2450,,10
    7788,"SCOTT","ANALYST",7566,19/04/1987 00:00:00,3000,,20
    7839,"KING","PRESIDENT",,17/11/1981 00:00:00,5000,,10
    7844,"TURNER","SALESMAN",7698,08/09/1981 00:00:00,1500,0,30
    7876,"ADAMS","CLERK",7788,23/05/1987 00:00:00,1100,,20
    7900,"JAMES","CLERK",7698,03/12/1981 00:00:00,950,,30
    7902,"FORD","ANALYST",7566,03/12/1981 00:00:00,3000,,20
    7934,"MILLER","CLERK",7782,23/01/1982 00:00:00,1300,,10The procedure allows for the header and data to go to seperate files if required. Just specifying the "header" filename will put the header and data in the one file.
    Adapt to output different datatypes and styles are required.

  • Replace xml code when used as a xmltype converted from clob.

    I am still new at all this so I will try to make sense.
    I have the "sys_xmlgen" where it takes my clob_content which is a clob and converts it into the v_xml which is xmltype.
    ****code to show change of clob to xmltype.
    SELECT sys_xmlgen(clob_content) INTO v_xml FROM xmltest2 WHERE item_id = v_item_id;
    update xmltest2 set xml = v_xml where item_id = v_item_id;
    **end of code
    When you use sys_xmlgen it changes the xml into this example:
    <?xml version="1.0"?>
    <CLOB_CONTENT>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
    &lt;!DOCTYPE metadata SYSTEM &quot;csdgm2.dtd&quot;&gt;
    &lt;?xml-stylesheet href=&quot;FGDC_V2.xsl&quot; type=&quot;text/xsl&quot;?&gt;
    &lt;metadata&gt;
    &lt;idinfo&gt;
    </CLOB_CONTENT>
    I need to remove the <CLOB_CONTENT> tag and change some things such as the "&lt;" to a "<" and so on. But when I do a replace statement
    select replace(clob_content, '&lt;', '<') into v_xml from xmltest2;
    It says I can not do a clob into number.
    Just to make myself clear, the clob_content is clob and v_xml is xmltype. SOOO I think that is where my problem is. Does anyone know the syntax to replace the code in my xml so that it looks like the original clob xml??
    Any help would be appreciated.

    I am still new at all this so I will try to make sense.
    I have the "sys_xmlgen" where it takes my clob_content which is a clob and converts it into the v_xml which is xmltype.
    ****code to show change of clob to xmltype.
    SELECT sys_xmlgen(clob_content) INTO v_xml FROM xmltest2 WHERE item_id = v_item_id;
    update xmltest2 set xml = v_xml where item_id = v_item_id;
    **end of code
    When you use sys_xmlgen it changes the xml into this example:
    ?xml version="1.0"?>
    <CLOB_CONTENT>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
    &lt;!DOCTYPE metadata SYSTEM &quot;csdgm2.dtd&quot;&gt;
    &lt;?xml-stylesheet href=&quot;FGDC_V2.xsl&quot; type=&quot;text/xsl&quot;?&gt;
    &lt;metadata&gt;
    &lt;idinfo&gt;
    &lt;citation&gt;
    &lt;citeinfo&gt;</CLOB_CONTENT>
    I need to remove the <CLOB_CONTENT> tag and change some things such as the "<" to a "<" and so on. But when I do a replace statement
    select replace(clob_content, '<', '<') into v_xml from xmltest2;
    It says I can not do a clob into number.
    Just to make myself clear, the clob_content is clob and v_xml is xmltype. SOOO I think that is where my problem is. Does anyone know the syntax to replace the code in my xml so that it looks like the original clob xml??
    Any help would be appreciated.

  • Convert utf8 char in a NSString

    Hi to all! I recieve from my server a XML file. I use NSXMLParser to retrieve attributes and values. The problem is this: i've many utf8 encoded char in many attributes, and i recieve them in NSStrings.
    //in - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict DELEGATE
    NSString *myAttribute = [[NSString alloc] initWithString:[attributeDict valueForKey:@"attribute"]];
    The NSString at key "attribute" can contain UTF8 char as ò and similar.
    How can i decode them to obtain a NSString with ò instead of ò and so on?

    I understood that you helped me, I will need to use
    parseInt to convert the string to number...No.
    Assuming you've got the "15:00" part, say in a String called timeStr, you'd just pass that to dateFormat.parse(timeStr)
    but I
    need to know where in the String are my numbers...
    isn't it? How may I do this? Well, that depends.
    What's your logic for finding it manually? Is it the first occurrence of any numerical digit in the string? Is it at a known, fixed character index? Some other logic?

  • Convert UTF8 to 8-bit intellegently

    I need to convert a UTF8 file into 8-bit.
    Of coarse, there is no way to do this perfectly, but it would be nice if there was a function that would make an intellegent substitution for characters that aren't in ASCII. For instance, the curly double quotes character would become a normal double quotes.
    I tried using String.getBytes("ISO-8859-1"), but it just subsitutes a question mark for all characters that aren't in ASCII.
    Anyone know of a function that can do this?

    just wrote Very long winded method for most of the common utf-8
    //list of unexcepted frequent chars: �����������������������������������������������������������
    StrAllData = StrAllData.replaceAll("�", "\"");
              StrAllData = StrAllData.replaceAll("�", "\"");
              StrAllData = StrAllData.replaceAll("�", "\'");
              StrAllData = StrAllData.replaceAll("�", "\'");      
              StrAllData = StrAllData.replaceAll("�", "A");                StrAllData = StrAllData.replaceAll("�", "A");
              StrAllData = StrAllData.replaceAll("�", "A");                StrAllData = StrAllData.replaceAll("�", "A");
              StrAllData = StrAllData.replaceAll("�", "E");                StrAllData = StrAllData.replaceAll("�", "E");
              StrAllData = StrAllData.replaceAll("�", "E");                StrAllData = StrAllData.replaceAll("�", "E");
              StrAllData = StrAllData.replaceAll("�", "I");                StrAllData = StrAllData.replaceAll("�", "I");
              StrAllData = StrAllData.replaceAll("�", "I");                StrAllData = StrAllData.replaceAll("�", "I");
              StrAllData = StrAllData.replaceAll("�", "N");                StrAllData = StrAllData.replaceAll("�", "O");
              StrAllData = StrAllData.replaceAll("�", "O");                StrAllData = StrAllData.replaceAll("�", "O");
              StrAllData = StrAllData.replaceAll("�", "A");                StrAllData = StrAllData.replaceAll("�", "E");      
              StrAllData = StrAllData.replaceAll("�", "E");                StrAllData = StrAllData.replaceAll("�", "E");      
              StrAllData = StrAllData.replaceAll("�", "E");               StrAllData = StrAllData.replaceAll("�", "I");      
              StrAllData = StrAllData.replaceAll("�", "I");                StrAllData = StrAllData.replaceAll("�", "B");      
              StrAllData = StrAllData.replaceAll("�", "I");                StrAllData = StrAllData.replaceAll("�", "N");      
              StrAllData = StrAllData.replaceAll("�", "a");                StrAllData = StrAllData.replaceAll("�", "O");      
              StrAllData = StrAllData.replaceAll("�", "a");               StrAllData = StrAllData.replaceAll("�", "a");
              StrAllData = StrAllData.replaceAll("�", "a");               StrAllData = StrAllData.replaceAll("�", "a");
         StrAllData = StrAllData.replaceAll("�", "a");               StrAllData = StrAllData.replaceAll("�", "c");               
         StrAllData = StrAllData.replaceAll("�", "e"); StrAllData = StrAllData.replaceAll("�", "e");
         StrAllData = StrAllData.replaceAll("�", "e");               StrAllData = StrAllData.replaceAll("�", "e");
              StrAllData = StrAllData.replaceAll("�", "e");               StrAllData = StrAllData.replaceAll("�", "i");
              StrAllData = StrAllData.replaceAll("�", "i");               StrAllData = StrAllData.replaceAll("�", "i");
              StrAllData = StrAllData.replaceAll("�", "i");               StrAllData = StrAllData.replaceAll("�", "n");               
              StrAllData = StrAllData.replaceAll("�", "o");               StrAllData = StrAllData.replaceAll("�", "o");
              StrAllData = StrAllData.replaceAll("�", "u");               StrAllData = StrAllData.replaceAll("�", "e");
              StrAllData = StrAllData.replaceAll("�", "o");               StrAllData = StrAllData.replaceAll("�", "u");
              StrAllData = StrAllData.replaceAll("�", "o");               StrAllData = StrAllData.replaceAll("�", "u");
              StrAllData = StrAllData.replaceAll("�", "o");               StrAllData = StrAllData.replaceAll("�", "u");
              StrAllData = StrAllData.replaceAll("�", "y");               StrAllData = StrAllData.replaceAll("�", "Z");               
              StrAllData = StrAllData.replaceAll("�", "o");               StrAllData = StrAllData.replaceAll("�", "y");
              StrAllData = StrAllData.replaceAll("�", "z");               StrAllData = StrAllData.replaceAll("�", "e");
              StrAllData = StrAllData.replaceAll("�", "S");               StrAllData = StrAllData.replaceAll("�", "o");
              StrAllData = StrAllData.replaceAll("�", "s");               StrAllData = StrAllData.replaceAll("�", "Y");

  • Converting PDF CLOBS to text or HTML

    I would like to run though all the PDFs (stored as CLOBS) in a database table and copy them to a text or HTML CLOB. Doing this beforehand will should allow me to rapidly index and snippet-ify these fields duirng queries.
    How exactly can I use the built-in facilities in Oracle Text to do this?
    Roger Ford has had some great input on my snippet performance problems and had this to say:
    "The key is to pre-convert before indexing. You can do that with a pl/sql procedure that uses ctxdoc.policy_filter or ctxdoc.ifilter."
    The Reference Manual, page B-2, has this to say:
    "This technology [AUTO_FILTER] also enables you to convert documents to HTML for document presentation with the CTX_DOC package."

    I apologize for posting prematurely....
    I should be able to use CTX_DOC.FILTER as Roger suggested.
    I think I can just loop through every PDF in the table and dump each converted PDF to the result table. I will set the query id to the key from the PDF table thus allowing me to get at the metadata.

  • Converting "UTF8" files to other encodings in Text Wrangler

    Hi and thanks for your help
    I have several text files I can easily use in different ways using Text Wrangler.
    I need to convert text files originally written with different enchodings and I get errors.
    I can overcome this using this script:
    tell application "TextWrangler"
       tell document 1
           set line breaks to Unix
           set encoding to "Cyrillic (Windows)"
       end tell
    end tell
    However my attempts to create a loop always return this error
    TextWrangler got an error: An unexpected error occurred while processing an Apple Event (MacOS Error code: -10000)
    What is wrong with my script?
    set inputfolder to (choose folder)
    set theFiles to list folder inputfolder without invisibles
    tell application "TextWrangler"
    repeat with x from 1 to count of theFiles
              set thefile to item x of theFiles
              set inputfile to quoted form of (POSIX path of inputfolder & thefile)
      set line breaks to Unix
           set encoding to "Cyrillic (Windows)"
       end tell
    end repeat

    If its not typo you have the end tell inside the end repeat. Should be the other way.
          set encoding to "Cyrillic (Windows)"
       end tell
    end repeat
    end
    That shouldn't even compile.

  • Converting a Clob to a String

    I've had a search around for ways to do this on the forum, but most of the posts only deal with the conversion of a String to a Clob.
    Is this conversion possible and does anybody have any pointers or know how to perform it?
    Thanks for your time,
    Tom.

    what's wrong with doing this:
    Clob c = rs.getClob("clobcol");
    String cValue = c.getSubString(0, c.length());

Maybe you are looking for

  • Updating tables in logical standby database

    Dear DBAs, Is it possible to update non replicated tables in the logical standby database, but have the same schema name? "Alter session disable guard" works only for the current session, in fact i want it for all connected users whithout stopping th

  • Using EFI password "full" security isn't working

    Hi, I'm trying to use the EFI Password Utility to prohibit any attempt to boot my MacBook Pro without the correct password.  I used the utility available on the MacBook Pro's supplied install DVD, and so far have successfully prevented the use of any

  • Is there a size limit to the HD that will be recognized?

    I want to add a 300 GB internal HD in an old G4 733 Quicksilver. The original HD is 40 GB. Will I have trouble with the system recognizing a hard drive of this size? If so, what can I do? or what are the limits to the size of a HD that I can install

  • How do I get my pics off iPad to free up memory

    I have an IPad with (16 gig) with wifi. I have a lot of pics on my iPad and need to get them off to free up memory to upgrade to the ios7. I have a windows pc. I down loaded ITunes app on the pc, but can not figure how to get them onto the pc. Would

  • HT1212 iPhone 4 is locked on ios7 and i forgot my password

    is there a way to bypass this if ive never synced it to my imac?