Setting clobs

how are clobs in java set?
setClob gives an error of setClob(int,javasql.Clob) in java.sql.PreparedStatement cannot be applied to (int, Java.lang.String)

That error means you are trying to pass a String instead of passing a CLOB. You need a CLOB as a second argument.

Similar Messages

  • Insert into CLOB fails with Oracle ODBC driver version 9.02.00.65

    I tried to insert into CLOB using the latest Oracle ODBC driver 9.02.00.65 and it fails. But the same works with earlier versions of ODBC driver earlier to 9.02.00.65 ie., 9.02.00.63.
    Here is the code snippet I tried. Any help now is highly appreciated as I am in the crunch time.
    I tried the same code snippet with VARCHAR2 column with the same driver and it works.
    ** CONVDSN.C - This is the ODBC sample code for
    ** creating File DSN pointers to machine DSNs.
    **This code is furnished on an as-is basis as part of the ODBC SDK and is
    **intended for example purposes only.
    #include <windows.h>
    #include <stdio.h>
    #include <tchar.h>
    #include <sql.h>
    #include <sqlext.h>
    #include <odbcinst.h>
    #include <sqltypes.h>
    #define MAXDATALEN 25 //maximum data length per column
    #define MAX_COL 15 //maximum column in result set
    #define MAX_ROW 100 //maximum number of rows
    #define MAXBUFLEN 256
    #define SQLERR_FORMAT "SQL Error State:%s, Native Error Code: %lX, ODBC Error: %s"
    #define MAXDISPLAYSIZE MAX_COL*(MAXDATALEN+1)
    #define SQLWRNMSGTITLE "SQL_SUCCESS_WITH_INFO results"
    #define SQLERRCNTDTITLE "SQL_ERROR results continued"
    #define SQLWRNMSGTITLE "SQL_SUCCESS_WITH_INFO results"
    #define SQLWRNCNTDTITLE "SQL_SUCCESS_WITH_INFO results continued"
    #define NULLDATASTRING "SQL_NULL_DATA"
    #define SQLERRMSGTITLE "SQL_ERROR results"
    // prototypes
    void ExpandFileName(LPSTR szFileDSNName, LPCSTR szDSNName);
    void MakeLegalName(LPSTR szLegalDSNName, LPCSTR szDSNName);
    // main routine: Iterate through the user and system DSNs, creating a pointer
    // to each.
    void FAR PASCAL DisplayError(SQLRETURN nResult, HWND hWnd, SWORD fHandleType, SQLHANDLE handle);
    void insertSelectClob();
    void checkRcCode(RETCODE rc);
    int main (int argc, char* argv[])
         insertSelectClob();
    return 0;
    void FAR PASCAL DisplayError(SQLRETURN nResult, HWND hWnd, SWORD fHandleType, SQLHANDLE handle)
         UCHAR szErrState[SQL_SQLSTATE_SIZE+1]; // SQL Error State string
         UCHAR szErrText[SQL_MAX_MESSAGE_LENGTH+1]; // SQL Error Text string
         char szBuffer[SQL_SQLSTATE_SIZE+SQL_MAX_MESSAGE_LENGTH+MAXBUFLEN+1];
         // formatted Error text Buffer
         SWORD wErrMsgLen; // Error message length
         UDWORD dwErrCode; // Native Error code
         int iSize; // Display Error Text size
         SQLRETURN nErrResult; // Return Code from SQLGetDiagRec
         SWORD sMsgNum = 1;
         SWORD fFirstRun = TRUE;
         char szDispBuffer[MAXDISPLAYSIZE+1]; // Display Buffer
         szBuffer[0] = '\0';
         do
              // continue to bring messageboxes till all errors are displayed.
              // more than one message box may be reqd. as err text has fixed
              // string size.
              // initialize display buffer with the string in error text buffer
              strcpy(szDispBuffer, szBuffer);
              // call SQLGetDiagRec function with proper ODBC handles, repeatedly until
              // function returns SQL_NO_DATA. Concatenate all error strings
              // in the display buffer and display all results.
              while ((nErrResult = SQLGetDiagRec(fHandleType, handle, sMsgNum++,
                   szErrState, &dwErrCode, szErrText,
                   SQL_MAX_MESSAGE_LENGTH-1, &wErrMsgLen)) != SQL_NO_DATA)
                   if(nErrResult == SQL_ERROR || nErrResult == SQL_INVALID_HANDLE)
                   break;
                   wsprintf(szBuffer, SQLERR_FORMAT, (LPSTR)szErrState, dwErrCode, (LPSTR)szErrText);
                   iSize = strlen(szDispBuffer);
                   if (iSize && (iSize+strlen(szBuffer)+1) >= MAXDISPLAYSIZE)
                   break;
                   if (iSize)
                   strcat(szDispBuffer, "\n");
                   strcat(szDispBuffer, szBuffer);
              // display proper ERROR or WARNING message with proper title
              if (nResult == SQL_SUCCESS_WITH_INFO)
                   MessageBox(hWnd, szDispBuffer, (fFirstRun? SQLWRNMSGTITLE : SQLWRNCNTDTITLE),
                   MB_OK | MB_ICONINFORMATION);
              else
                   MessageBox(hWnd, szDispBuffer, (fFirstRun? SQLERRMSGTITLE : SQLERRCNTDTITLE),
                   MB_OK | MB_ICONEXCLAMATION);
              if (fFirstRun)
                   fFirstRun = FALSE;
         while (!(nErrResult == SQL_NO_DATA || nErrResult == SQL_ERROR || nErrResult == SQL_INVALID_HANDLE));
    void insertSelectClob()
    SQLCHAR clobdata[1001];
    SQLCHAR resultdata[1001];
    SQLINTEGER ind = SQL_DATA_AT_EXEC;
    SQLCHAR *bufp;
         SQLINTEGER cbOrderID = sizeof(SQLSMALLINT);
         SQLSMALLINT sTmp=13;
         SQLCHAR *sqlStmt1  = _T("INSERT INTO clobtbl(id, clob1) VALUES(?, ?)");
         SQLCHAR *sqlStmt2  = _T("SELECT id, clob1 FROM clobtbl");
    //     SQLCHAR *sqlStmt1  = _T("INSERT INTO testInsert(id, clob1) VALUES(?, ?)");
    // SQLCHAR *sqlStmt2  = _T("SELECT id, clob1 FROM testInsert");
    int clobdatalen, chunksize, dtsize, retchklen;
         HENV envHnd;
    HDBC conHnd;
    HSTMT stmtHnd;
    RETCODE rc;
         int nRowcnt=0;
         SQLPOINTER pToken = NULL;
    rc = SQL_SUCCESS;
    // ENV is allocated
    rc = SQLAllocEnv(&envHnd);
    // Connection Handle is allocated
    rc = SQLAllocConnect(envHnd, &conHnd);
    rc = SQLConnect(conHnd, T("testd734"), SQLNTS, T("ipathdba"), SQLNTS, T("ipathdba"), SQLNTS);
    printf(_T("Insert CLOB1 using SQLPutData...\n[%s]\n"), sqlStmt1);
    // Set CLOB Data
    int i;
    SQLCHAR ch;
    for (i=0, ch=_T('A'); i< sizeof(clobdata)/sizeof(SQLCHAR); ++i, ++ch)
    if (ch > _T('Z'))
    ch = _T('A');
    clobdata[i] = ch;
    clobdata[sizeof(clobdata)/sizeof(SQLCHAR)-1] = _T('\0');
    clobdatalen = lstrlen(clobdata); // length of characters
    chunksize = clobdatalen / 7; // 7 times to put
         rc = SQLAllocHandle(SQL_HANDLE_STMT, conHnd, &stmtHnd);
    // Step 1: Prepare
    rc = SQLPrepare(stmtHnd, sqlStmt1, SQL_NTS);
    // checkSQLErr(envHnd, conHnd, stmtHnd, rc);
    // Step 2: Bind Parameter with SQL_DATA_AT_EXEC
    rc = SQLBindParameter(stmtHnd,
    1,
    SQL_PARAM_INPUT,
    SQL_C_SSHORT,
    SQL_INTEGER,
    0,
    0,
    &sTmp,
    0,
    &cbOrderID);
    rc = SQLBindParameter(stmtHnd,
    2,
    SQL_PARAM_INPUT,
    SQL_C_CHAR,
    SQL_LONGVARCHAR,
    clobdatalen*sizeof(CHAR),
    0,
    (SQLPOINTER)clobdata,
    clobdatalen*sizeof(CHAR),
    &ind);
    // checkSQLErr(envHnd, conHnd, stmtHnd, rc);
    // Step 3: Execute
    rc = SQLExecute(stmtHnd);
         while (rc == SQL_NEED_DATA) {
              rc = SQLParamData(stmtHnd, &pToken);
              if (rc == SQL_NEED_DATA) {
                   for (dtsize=0, bufp = clobdata;
                        dtsize < clobdatalen;
                        dtsize += chunksize, bufp += chunksize)
                   int len;
                   if (dtsize+chunksize < clobdatalen)
                        len = chunksize;
                        rc = SQLPutData(stmtHnd, bufp, len*sizeof(SQLCHAR));
                   else
                        len = clobdatalen-dtsize;
                        rc = SQLPutData(stmtHnd, bufp, SQL_NTS);
              rc = SQLParamData(stmtHnd, &pToken);
    // Fails as row count retrieved is zero.
         rc = SQLRowCount(stmtHnd, &nRowcnt);
         if(rc != SQL_SUCCESS)
              DisplayError(rc, NULL, SQL_HANDLE_ENV, conHnd);
    rc = SQLFreeStmt(stmtHnd, SQL_CLOSE);
    printf(_T("Finished Update\n\n"));
    rc = SQLAllocStmt(conHnd, &stmtHnd);
    if (rc != SQL_SUCCESS)
    printf(_T("Failed to allocate STMT\n"));
    exit(-1);
    // Clear Result Data
    memset(resultdata, 0, sizeof(resultdata));
    chunksize = clobdatalen / 15; // 15 times to gut
    rc = SQLExecDirect(stmtHnd, sqlStmt2, SQL_NTS); // select
         if(rc != SQL_SUCCESS)
              DisplayError(rc, NULL, SQL_HANDLE_ENV, conHnd);
    // Step 2: Fetch
    rc = SQLFetch(stmtHnd);
    for(dtsize=0, bufp = resultdata;
    dtsize > sizeof(resultdata)/sizeof(CHAR) && rc != SQL_NO_DATA;
    dtsize += chunksize-1, bufp += chunksize-1)
    int len; // len should contain the space for NULL termination
    if (dtsize+chunksize<sizeof(resultdata)/sizeof(CHAR))
    len = chunksize;
    else
    len = sizeof(resultdata)/sizeof(CHAR)-dtsize;
    // Step 3: GetData
    rc = SQLGetData(stmtHnd,
    2,
    SQL_C_CHAR,
    (SQLPOINTER)bufp,
    len*sizeof(CHAR),
    &retchklen);
    if (!_tcscmp(resultdata, clobdata))
    printf(_T("Succeeded!!\n\n"));
    else
    printf(_T("Failed!!\n\n"));
         if (conHnd)
              SQLFreeConnect(conHnd);
         if (envHnd)
              SQLFreeEnv(envHnd);
    }

    Hi,
    Since 9.2 has been desupported for error correction you will not be able to download that version from OTN. You should ask whoever is providing the training if their is an alternate version you can use. The only versions that you will be able to download from oracle.com is 10.2 11.1, and 11.2.

  • Portal 4.0 with MS SQL Server 2000 using CLOBs

    Hello,
    I'm driving Portal 4.0 with MS SQL Server 2000. I have encountered serious
    problems when trying to persist events (e.g. RuleEvent) to database. In my
    application-config.xml file I have JdbcHelper attributes
    ShouldUseClobsForReads & -Writes set to 'false' as they should be or
    mssqlserver4v70 driver.
    It seems that when it is time to write the event to database, Portal4.0
    can't find JdbcHelper MBean configuration values and therefore it uses
    default values (=true) for both attributes.
    Otherwise reading and writing works fine with MS SQL Server 2000 (at least
    DATA_SYNC_ITEMs).
    Any help appreciated.
    Regards,
    JR
    P.S.
    Here are some excerpts from the console output:
    [BufferManager$PersistenceRequest.execute():247]
    PersistenceRequest::execute -> write to database
    [AbstractDatabasePersister.persist():135] Persister::persist -> write the
    events. size=2
    *** com.bea.p13n.util.jdbc.JdbcHelper.getInstance() @ JdbcHelper.java:122
    [JdbcHelper.getInstance():139] No instance found for
    sun.misc.Launcher$AppClassLoader@71732b
    [JdbcHelper.<init>():111] Unable to find JdbcHelper Configuration ...using
    defaults: java.lang.IllegalStateException: Not in application context
    at
    com.bea.p13n.management.ApplicationHelper.getApplicationName(ApplicationHelp
    er.java:119)
    at
    com.bea.p13n.management.ApplicationHelper.getApplicationConfigurationMBean(A
    pplicationHelper.java:440)
    at
    com.bea.p13n.management.ApplicationHelper.getServiceConfigurationMBean(Appli
    cationHelper.java:318)
    at com.bea.p13n.util.jdbc.JdbcHelper.<init>(JdbcHelper.java:102)
    at
    com.bea.p13n.util.jdbc.JdbcHelper.getInstance(JdbcHelper.java:141)
    at
    com.bea.p13n.util.jdbc.JdbcHelper.getConnection(JdbcHelper.java:265)
    at
    com.bea.p13n.tracking.internal.persistence.AbstractDatabasePersister.getConn
    ection(AbstractDatabasePersister.java:202)
    at
    com.bea.p13n.tracking.internal.persistence.AbstractDatabasePersister.persist
    (AbstractDatabasePersister.java:140)
    at
    com.bea.p13n.tracking.internal.persistence.BufferManager$PersistenceRequest.
    execute(BufferManager.java:250)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
    *** com.bea.p13n.util.jdbc.JdbcHelper.getInstance() @ JdbcHelper.java:122
    [JdbcHelper.getInstance():131] Got instance for
    sun.misc.Launcher$AppClassLoader@71732b
    [JdbcHelper._setClob():412] ######## JdbcHelper: String length = 496
    [JdbcHelper._setClob():420] ######## JdbcHelper: setting CLOB String with
    setCharacterStream()
    <7.1.2002 14:27:41 GMT+02:00> <Error> <Tracking> <Error persisting event to
    database. java.sql.SQLException: java.sql.SQLException: This JDBC 2.0 method
    is not implemented
    at
    weblogic.jdbc.rmi.SerialPreparedStatement.setCharacterStream(SerialPreparedS
    tatement.java:428)
    at com.bea.p13n.util.jdbc.JdbcHelper._setClob(JdbcHelper.java:424)
    at com.bea.p13n.util.jdbc.JdbcHelper.setClob(JdbcHelper.java:404)
    at
    com.bea.p13n.tracking.internal.persistence.BehaviorTrackingPersister.setPrep
    aredStatementData(BehaviorTrackingPersister.java:93)
    at
    com.bea.p13n.tracking.internal.persistence.AbstractDatabasePersister.persist
    (AbstractDatabasePersister.java:157)
    at
    com.bea.p13n.tracking.internal.persistence.BufferManager$PersistenceRequest.
    execute(BufferManager.java:250)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)

    Hi,
    I would suggest better to have a backup of existing database remove your existing SQL server. Install the  one given by SAP. And restore your previous databases.
    --Ragu

  • The ADO NET Source was unable to process the data. ORA-64203: Destination buffer too small to hold CLOB data after character set conversion.

     We developed a SSIS Package to pull the data From Oracle source to Sql Server 2012. Here we used ADO.Net source to pull the records from Source but getting the below error after pulling some 40K records.
      [ADO NET Source [2]] Error: The ADO NET Source was unable to process the data. ORA-64203: Destination buffer too small to hold CLOB data after character set conversion.
    [SSIS.Pipeline] Error: SSIS Error Code DTS_E_PRIMEOUTPUTFAILED. 
     The PrimeOutput method on ADO NET Source returned error code 0xC02090F5. 
     The component returned a failure code when the pipeline engine called PrimeOutput(). 
    The meaning of the failure code is defined by the component, 
    but the error is fatal and the pipeline stopped executing. 
     There may be error messages posted before this with more 
    information about the failure.
    Anything that we can do to fix this?

    Hi,
      Tried both....
      * Having schema type as Nvarchar(max). - Getting the same error.
      * Instead of ADO.Net Source used OLEDB Source with driver as " Oracle Provide for OLE DB" Getting error as below.
           [OLE DB Source [478]] Error: SSIS Error Code DTS_E_OLEDBERROR.  An OLE DB error has occurred. Error code: 0x80004005.
           [SSIS.Pipeline] Error: SSIS Error Code DTS_E_PRIMEOUTPUTFAILED.  The PrimeOutput method on OLE DB Source returned error code 0xC0202009.  The component returned a failure
    code when the pipeline engine called PrimeOutput(). The meaning of the failure code is defined by the component, but the error is fatal and the pipeline stopped executing.  There may be error messages posted before this with more information about the
    failure.
    Additional Info:
       * Here the Source task is getting failed not the conversion or destination task.
    Thanks,
    Loganathan A.

  • XML data from BLOB to CLOB - character set conversion

    Hi All,
    I'm trying to solve a problem with a character set conversion in PL/SQL in the following scenario:
    1. source is an XML as a BLOB variable.
    2. target is an XML as a CLOB variable.
    3. the problem I have is the following:
    - database character set is set to UTF-8
    - XML character set could be anything (UTF-8, ISO 8859-1, ISO 8859-2, ASCII, ...)
    - I need to write a procedure which converts the source BLOB content into the target CLOB taking into account the XML encoding and converts it into the DB default character set (UTF8).
    I've been able to implement a simple conversion function. However, this function expects static XML encoding ISO-8859-1. The main part of the function looks as follows:
    buffer := UTL_RAW.cast_to_varchar2(
    UTL_RAW.convert(
    DBMS_LOB.SUBSTR(source_blob_variable, 16000, pos)
    , 'American_America.UTF8'
    , 'American_America.we8iso8859p1')
    Does anyone have an idea how to rewrite the code to handle "any" XML encoding in the source BLOB file? In other words, is there a function in Oracle which converts XML character set names into Oracle character set values (ISO-8859-1 to we8iso8859p1, UTF-8 to UTF8, ...)?
    Thanks a lot for any help.
    Julius

    I want to pass a BLOB to some "createXML" procedure and get a proper XMLType in UTF8 character set, properly converted from whatever character set is the input in.As per documentation the generated XML has always the encoding set at the client side depending on NLS_LANG (default UTF-8), regardless of the input encoding, so I don't see a need to parse the PI of the XML:
    C:\>echo %NLS_LANG%
    %NLS_LANG%
    C:\>sqlplus
    SQL*Plus: Release 11.1.0.6.0 - Production on Wed Apr 30 08:54:12 2008
    Copyright (c) 1982, 2007, Oracle.  All rights reserved.
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> var cur refcursor
    SQL>
    SQL> declare
      2     b   blob := utl_raw.cast_to_raw ('<a>myxml</a>');
      3  begin
      4     open :cur for select xmlroot (xmltype (utl_raw.cast_to_varchar2 (b))) xml from dual;
      5  end;
      6  /
    PL/SQL procedure successfully completed.
    SQL>
    SQL> print cur
    XML
    <?xml version="1.0" encoding="UTF-8"?><a>myxml</a>
    SQL> exit
    Disconnected from Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    C:\>set NLS_LANG=GERMAN_GERMANY.WE8ISO8859P1
    C:\>sqlplus
    SQL*Plus: Release 11.1.0.6.0 - Production on Mi Apr 30 08:55:02 2008
    Copyright (c) 1982, 2007, Oracle.  All rights reserved.
    SQL> var cur refcursor
    SQL>
    SQL> declare
      2     b   blob := utl_raw.cast_to_raw ('<a>myxml</a>');
      3  begin
      4     open :cur for select xmlroot (xmltype (utl_raw.cast_to_varchar2 (b))) xml from dual;
      5  end;
      6  /
    PL/SQL-Prozedur erfolgreich abgeschlossen.
    SQL>
    SQL> print cur
    XML
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <a>myxml</a>

  • Setting Line Terminator for a CLOB column by script

    Hello Everyone,
    I have a CLOB column in my table that receives external data (more than 400 sources).
    The GUI application displays it in different ways because of the multiple incoming Line Terminators.
    Here is the weird thing:
    In SQL developper 3.1.06. In the Preferences->Environment I selected as Line Terminator: Carriage Return and Line Fe(Windows)
    Once I committed the changes the data was properly displayed in the application (apparently was also re-coded).
    My Question is:
    How can I setup this property on the column or table to fix the issue??
    (I'm looking for a DDL script or something alike).
    Thanks in advance.
    Mijail O. T.

    914451 wrote:
    If that's the case, What is the SQL DEveloper doing then??
    I tested and looks like is a global parameter, not sure if works only for the table. (That what I need).
    If is possible to setup this feature from the GUI it should be a way to do it running a Script.
    Right????No.
    Tables don't have any concept of "lines".
    CLOB's don't have any concept of "lines".
    "lines" only exist in the context of the data you are providing, but that's not of concern to the database.
    So it looks like, what SQL Developer is doing (I assume as I don't use it), is to have a setting such that when it comes to display character data from VARCHAR2's or CLOB's it determines if there are CR/LF or just LF characters (as per the setting) and then uses those as line terminators for displaying the data in it's own interface. Thus it sounds like an interface specific setting, or to put it bluntly, it's something that is a part of SQL Developer to control how it displays things.
    Have you tried querying back the raw version of the data from the database to see that it still has the CR/LF characters in it? It should.
    I think you'll find the setting is a "display" setting, not a "alter my data" setting.

  • How to set a clob value to a hidden field

    I have a function returning a clob value . Please let me know if there is a way to set a hidden variable with a clob value.

    Hi,
    This functionality is known to be very important and is a key part of the next major release of the JRC planned for the first half of 2008.
    Regards,
    <p>Blair Wheadon</p>
    <p>Product Manager, Crystal Reports</p>

  • Setting of CLOB Datatype storage space

    Hello All!
    I unble to insert more then 4000 characters in clob datatype field
    how I increate the storage size of the clob field
    I'm working in VB 6.0 and oracle 9i

    Oracle will allocate CLOB segments using some default storage options linked to column, table and tablespace.
    Example with Oracle 11.2 XE:
    SQL> select * from v$version;
    BANNER
    Oracle Database 11g Express Edition Release 11.2.0.2.0 - Beta
    PL/SQL Release 11.2.0.2.0 - Beta
    CORE    11.2.0.2.0      Production
    TNS for 32-bit Windows: Version 11.2.0.2.0 - Beta
    NLSRTL Version 11.2.0.2.0 - Production
    SQL> create user test identified by test;
    User created.
    SQL> grant create session, create table to test;
    Grant succeeded.
    SQL> alter user test quota unlimited on users;
    User altered.
    SQL> alter user test default tablespace users;
    User altered.
    SQL> connect test/test;
    Connected.
    SQL> create table tl(x clob);
    Table created.
    SQL> column segment_name format a30
    SQL> select segment_name, bytes/(1024*1024) as mb
      2  from user_segments;
    SEGMENT_NAME                           MB
    TL                                  ,0625
    SYS_IL0000020403C00001$$            ,0625
    SYS_LOB0000020403C00001$$           ,0625
    SQL> insert into tl values('01234456789');
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> select segment_name, bytes/(1024*1024) as mb
      2  from user_segments;
    SEGMENT_NAME                           MB
    TL                                  ,0625
    SYS_IL0000020403C00001$$            ,0625
    SYS_LOB0000020403C00001$$           ,0625
    SQL>Same example run with Oracle XE 10.2 :Re: CLOB Datatype [About Space allocation]
    Edited by: P. Forstmann on 24 juin 2011 09:24

  • Urgent: How to set a default value to CLOB field?

    Hi All,
    As per the requirements we have to populate the CLOB field in a template with default value with some template similar to a letter issued to clients in bank.
    So, every time when I insert a record in that table this CLOB field should have that letter template populated by default and user will modify that if required from GUI.
    How can I populate that CLOB field by default?
    Thanks!

    Something like this?
    ME_XE?
    create table test_clob
      pk_value number primary key,
      one_clob clob   default rpad('something', 32000, '*')
    insert into test_clob (pk_value) values (1);
    select * from test_clob;
    Table created.
    Elapsed: 00:00:00.13
    ME_XE?ME_XE?
    1 row created.
    Elapsed: 00:00:00.09
    ME_XE?ME_XE?
              PK_VALUE ONE_CLOB
                     1 something***********************************************************************
    1 row selected.
    Elapsed: 00:00:02.65
    ME_XE?ME_XE?
    ME_XE?ME_XE?select * from v$version;
    BANNER
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product
    PL/SQL Release 10.2.0.1.0 - Production
    CORE     10.2.0.1.0     Production
    TNS for Linux: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production
    5 rows selected.
    Elapsed: 00:00:00.18
    ME_XE?

  • How do I set a maximum length (in characters) of a CLOB field

    Hi,
    I've seen some questions like this around, but I did not find a clear answer.
    This is my problem: I want to make my CLOB field to accept a maximum of 32768 characters. This is because I need other data manipulation tools to receive an ORA error when they try to insert or update text larger than 32768.
    I tried with an Insert/Update trigger, but I received ORA error that actually means that LOB fields can not be used in update trigger(or something).
    Please, help!

    Maybe, Not a neat way to do things, but seems to work.
    Others may be able to suggest better solutions.
    SQL> create table test_lob(lob clob) ;
    Table created.
    SQL> CREATE OR REPLACE FUNCTION getlength(p_lob CLOB) RETURN NUMBER DETERMINISTIC IS
      2  BEGIN
      3      IF (dbms_lob.getlength(p_lob) > 32768)
      4      THEN
      5          raise_application_error(-20100,
      6                                  'Text may not be greater than 32768 characters!');
      7      ELSE
      8          RETURN NULL;
      9      END IF;
    10  END;
    11  /
    Function created.
    SQL> create index idx_test_lob on test_lob(getlength(lob)) ;
    Index created.
    SQL>
    SQL> declare
      2    l_lob CLOB ;
      3  begin
      4    insert into test_lob values (empty_clob()) returning lob into l_lob ;
      5    dbms_lob.writeappend(l_lob, 32767, rpad('*', 32767, '*')) ;
      6  end ;
      7  /
    PL/SQL procedure successfully completed.
    SQL> declare
      2    l_lob CLOB ;
      3  begin
      4    insert into test_lob values (empty_clob()) returning lob into l_lob ;
      5    dbms_lob.writeappend(l_lob, 32760, rpad('*', 32760, '*')) ;
      6    dbms_lob.writeappend(l_lob, 8, rpad('*', 8, '*')) ;
      7  end ;
      8  /
    PL/SQL procedure successfully completed.
    SQL> declare
      2    l_lob CLOB ;
      3  begin
      4    insert into test_lob values (empty_clob()) returning lob into l_lob ;
      5    dbms_lob.writeappend(l_lob, 32760, rpad('*', 32760, '*')) ;
      6    dbms_lob.writeappend(l_lob, 9, rpad('*', 9, '*')) ;
      7  end ;
      8  /
    declare
    ERROR at line 1:
    ORA-20100:
    ORA-06512: at "SYS.DBMS_LOB", line 789
    ORA-06512: at line 6
    SQL> select count(*) from test_lob ;
      COUNT(*)
             2
    1 row selected.
    SQL>

  • Query to read XML from CLOB table column

    Hi
    I want an SQL to get the following information extract from a CLOB table column.
    MasterReport/sg:RptDef/sg:RptCell@RealDesc MasterReport/sg:RptDef/sg:RptCell@RealNum
    credits                              100
    debits                              100
    Sample XML data from table column is:
    <?xml version="1.0" encoding="UTF-8" ?>
    <MasterReport xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sg="http://www.oracle.com/fsg/2002-03-20/" xsi:schemaLocation="http://www.oracle.com/2002-03-20/fsg.xsd">
    <sg:LDGName>Vision Portugal</sg:LDGName>
    <sg:SOBName>Vision Portugal</sg:SOBName>
    <sg:DataAccessSetName>Vision Portugal</sg:DataAccessSetName>
    <sg:InternalReportName>Model 30 Report</sg:InternalReportName>
    <sg:CustomParam10 />
    <sg:RowContext RowId="r100001">
    <sg:RowName />
    <sg:RowLineItem>Litigation Credits- Total amount from previous period</sg:RowLineItem>
    <sg:RowDispUnit>1</sg:RowDispUnit>
    <sg:RowDispFormat />
    <sg:RowUnitOfMeasure>EUR</sg:RowUnitOfMeasure>
    <sg:RowLedgerCurrency>ANY</sg:RowLedgerCurrency>
    <sg:RowCurrencyType>T</sg:RowCurrencyType>
    <sg:RowChangeSign>0</sg:RowChangeSign>
    <sg:RowSeq>1.0000000000000</sg:RowSeq>
    </sg:RowContext>
    <sg:RowContext RowId="r100002">
    <sg:RowName />
    <sg:RowLineItem>Litigation credits- Taxed amounts from column2 for Previous period</sg:RowLineItem>
    <sg:RowDispUnit>1</sg:RowDispUnit>
    <sg:RowDispFormat />
    <sg:RowUnitOfMeasure>EUR</sg:RowUnitOfMeasure>
    <sg:RowLedgerCurrency>ANY</sg:RowLedgerCurrency>
    <sg:RowCurrencyType>T</sg:RowCurrencyType>
    <sg:RowChangeSign>0</sg:RowChangeSign>
    <sg:RowSeq>2.0000000000000</sg:RowSeq>
    </sg:RowContext>
    <sg:ColContext ColId="c1000">
    <sg:ColAmountType />
    <sg:ColPeriod />
    <sg:ColPerOffset />
    <sg:ColChangeSign />
    <sg:ColPosition />
    <sg:ColSeq />
    <sg:ColWidth>100</sg:ColWidth>
    </sg:ColContext>
    <sg:ColContext ColId="c1001">
    <sg:ColName>Total</sg:ColName>
    <sg:ColDescr />
    <sg:ColDispUnit>1</sg:ColDispUnit>
    <sg:ColUnitOfMeasure>EUR</sg:ColUnitOfMeasure>
    <sg:ColLedgerCurrency>ANY</sg:ColLedgerCurrency>
    <sg:ColCurrencyType>T</sg:ColCurrencyType>
    <sg:ColDispFormat>999999999.99</sg:ColDispFormat>
    <sg:ColAmountType>YTD-Actual</sg:ColAmountType>
    <sg:ColPerOffset>0</sg:ColPerOffset>
    <sg:ColAmntId>14</sg:ColAmntId>
    <sg:ColParamId>-1</sg:ColParamId>
    <sg:ColType>A</sg:ColType>
    <sg:ColStyle>B</sg:ColStyle>
    <sg:ColPeriod>10-08</sg:ColPeriod>
    <sg:ColPeriodYear>2008</sg:ColPeriodYear>
    <sg:ColPeriodNum>11</sg:ColPeriodNum>
    <sg:ColPeriodStart>2008-10-01T00:00:00</sg:ColPeriodStart>
    <sg:ColPeriodEnd>2008-10-31T00:00:00</sg:ColPeriodEnd>
    <sg:ColChangeSign>0</sg:ColChangeSign>
    <sg:ColHeadLine1>Totals</sg:ColHeadLine1>
    <sg:ColHeadLine2 />
    <sg:ColHeadLine3 />
    <sg:ColHeadLine4 />
    <sg:ColHeadLine5 />
    <sg:ColHeadLine6 />
    <sg:ColHeadLine7 />
    <sg:ColHeadLine8 />
    <sg:ColHeadLine9 />
    <sg:ColPosition>99</sg:ColPosition>
    <sg:ColSeq>1.0000000000000</sg:ColSeq>
    <sg:ColWidth>14</sg:ColWidth>
    </sg:ColContext>
    <sg:RptDef RptId="p1001" RptDetName="Ledger=Vision PT (Vision Portugal)" RptPESegm="" RptPEVal="" RptTabLabel="Output 1 (Vision PT)">
    <sg:RptLine RptCnt="p1001" RowCnt="r100001" LineRowSeq="1.0000000000000" LinCnt="l100001">
    <sg:RptCell ColCnt="c1000" RealDesc="debits">debits</sg:RptCell>
    <sg:RptCell ColCnt="c1001" RealNum="100.000000">100.00</sg:RptCell>
    </sg:RptLine>
    <sg:RptLine RptCnt="p1001" RowCnt="r100002" LineRowSeq="2.0000000000000" LinCnt="l100002">
    <sg:RptCell ColCnt="c1000" RealDesc="creditsd">credits</sg:RptCell>
    <sg:RptCell ColCnt="c1001" RealNum="100.000000">100.00</sg:RptCell>
    </sg:RptLine>
    </sg:RptDef>
    <sg:TabCount>1</sg:TabCount>
    </MasterReport>
    Please help me.
    Regards
    Giri
    Edited by: user576087 on Mar 18, 2012 11:54 PM

    I'm not sure if you want the values from the attribute or the element, but this should give you a good start :
    SQL> alter session set nls_numeric_characters = ".,";
    Session altered
    SQL>
    SQL> select x.*
      2  from my_table t
      3     , xmltable(
      4         xmlnamespaces('http://www.oracle.com/fsg/2002-03-20/' as "sg")
      5       , '/MasterReport/sg:RptDef/sg:RptLine'
      6         passing xmltype(t.xmldoc)
      7         columns type    varchar2(30) path 'sg:RptCell[1]'
      8               , amount  number       path 'sg:RptCell[2]'
      9       ) x
    10  ;
    TYPE                               AMOUNT
    debits                                100
    credits                               100

  • Help!!urgent!!can not insert/update clob:the row containing the lob is not locked

    Hi,
    could you do me help?
    i can not insert a string into a oracle clob field, it echo as:
    ORA22920 row containing the lob value is not locked. ORA 06512 at "SYS.DBMS_LOB" line 708
    ORA 06512 at line 1;
    what its means? please.
    my table defined as : create table clob1(id number(5),mclob clob default empty_clob()); the id is create by a sequece of test_sequence automaticly.
    my code as belows:
    import java.io.*;
    import java.sql.*;
    //import oracle.sql.*;
    public class test4 {
    public static void main(String args[]) {
    String url_String
    = "jdbc:oracle:thin:test/test@myhost:1521:myorcl";
    try {
    Class.forName
    ("oracle.jdbc.driver.OracleDriver");
    java.sql.Connection con =
    java.sql.DriverManager.getConnection(url_String);
    con.setAutoCommit(true);
    Statement stmt
    =con.createStatement();
    String sqlStr ="insert into
    clob1 (mclob) " + "values(empty_clob())";
    stmt.executeUpdate(sqlStr);
    String query = "select
    test_seq.CURRVAL from dual";
    ResultSet rs =stmt.executeQuery
    (query);
    rs.next();
    int currval =rs.getInt(1);
    query = "select * from clob1 where
    id="+currval;
    String str
    ="abcedefhijklmnopqrstuvwxyz";
    rs =stmt.executeQuery(query);
    rs.next();
    java.sql.Clob clob1
    =rs.getClob(2);
    oracle.sql.CLOB clob=
    (oracle.sql.CLOB)clob1;
    System.out.print(clob);
    java.io.Writer
    wr=clob.getCharacterOutputStream();
    wr.write(str);
    wr.flush();
    wr.close();
    stmt.close();
    con.close();
    } catch(Exception ex) {
    System.err.println("SQLException: "
    + ex.getMessage());
    null

    Hi,
    To avoid ORA-22920 error while selecting lob column, use the 'for update' clause in the select statement like :
    query = "select * from clob1 where id="+currval+" FOR UPDATE" ;
    This should solve the problem. However, after fixing this, you might get the error :
    java.sql.SQLException: ORA-1002: fetch out of sequence
    I got this error when testing your code. To avoid this error, before executing 'select ... for update' statement Set AutoCommit to OFF, like :
    query = "select * from clob1 where id="+currval+" FOR UPDATE" ;
    con.setAutoCommit(false);
    rs =stmt.executeQuery(query);
    Hope that Helps,
    Srinivas

  • PL/SQL Limit When Dealing with a CLOB?

    Greetings,
    I am constructing HTML into a CLOB in a PL/SQL routine which I later display in an APEX application. The HTML can get large, because I am constructing a grid over an image, and the grid can have a lot of columns and rows which means there can be a lot of <area shape="rect" HTML lines. I did a search and found that another person had the same problem, because there is a 32K limit with HTML contents. That was very helpful.
    Thing is - I have another (maybe similar) issue. The procedure that constructs the HTML gets a numeric error when the number of cells in the grid reach a certain point. I checked and this happens when the CLOB in the procedure gets close to 32K. Sorry, it difficult to know exactly when it fails, but the most I have been able to put into the CLOB is 32,852 characters. Therefore my question - is there in internal limit in PL/SQL (or some other Oracle aspect) that is limited to 32K? The coluimn in the table that contains the HTML is a CLOB and the variable in the PL/SQL that the HTML is parsed into is a CLOB, so I thought I was good to go since the CLOB limit is 4GB. But, it looks like I may be missing something.
    We are running Oracle 11i and APEX 4.0.2.00.07. If other system info is needed let me know and I will get that for you.
    Also, if it helps. The code from the procedure is copied below. v_html is the variable that holds the HTML. The table column for the HTML is imagemap_html. Both v_html and imagemap_html are defined as CLOB's.
    Thanks, Tony
    = = = = = = =
    create or replace
    procedure create_grid (p_action IN VARCHAR2) as
        v_wcount integer := 0;   
        v_wmax integer := 20;
        v_width integer := 720;
        v_w1 integer := 0;
        v_w2 integer := 0;
        v_winc integer := 0;
        v_wstart integer := 0;
        v_wend integer := 0;   
        v_hcount integer := 0;
        v_hmax integer := 10;
        v_height integer := 520;
        v_h1 integer := 0;
        v_h2 integer := 0;
        v_hinc integer := 0;
        v_hstart integer := 0;
        v_hend integer := 0;   
        v_cell_row integer := 0;
        v_cell_col integer := 0;
        v_cell_title varchar2(10) := NULL;
        v_whitespace varchar2(10) := NULL;
        v_url_1 varchar2(100) := NULL;
        v_url_2 varchar2(100) := NULL;
        v_url_3 varchar2(100) := NULL;
        v_brand_id integer := 0;
        v_division_id integer := 0;
        v_plant_id integer := 0;
        v_model_id integer := 0;
        v_acc_group integer := 0;
        v_accessory integer := 0;
        v_acc_grp integer := 0;
        v_acc integer := 0;
        v_station_id integer := 0;
        v_substation_id integer := 0;     
        v_image_id integer := 0;
        v_id integer := 0;  
        v_html clob;
      begin
      v_brand_id := v('P4_BRAND_ID');
      v_division_id :=v('P4_DIVISION_ID');
      v_plant_id := v('P4_PLANT_ID');
      v_model_id := v('P4_MODEL_ID');
      v_acc_group := v('P4_ACC_GROUP');
      v_accessory := v('P4_ACCESSORY');
      v_station_id := v('P4_STATION_ID');
      v_substation_id := v('P4_SUBSTATION_ID');
      v_image_id := v('P4_IMAGES_ID');
      v_wmax := v('P4_COLUMNS');
      v_hmax := v('P4_ROWS');
      v_wstart := v('P4_XSTART');
      v_hstart := v('P4_YSTART');
      v_wend := v('P4_XEND');
      v_hend := v('P4_YEND'); 
      v_whitespace := v('P4_WHITESPACE');
    if p_action = 'INSERT' then
    -- insert the row now, so that the cell table rows can be inserted with the correct FK 
    insert into IM_TEMPLATE_DRAFT
    (plant_id, brand_id, division_id, model_id, acc_group, accessory, station_id,
    substation_id, image_id)
    values
    (v_plant_id,v_brand_id,v_division_id,v_model_id,v_acc_group,v_accessory,v_station_id,v_substation_id,v_image_id);
    commit;
    end if;
    -- get the id of the row that was just inserted
    select header_id into v_id from  IM_TEMPLATE_DRAFT where
    plant_id=v_plant_id and brand_id=v_brand_id and division_id=v_division_id and
    model_id=v_model_id and acc_group=v_acc_group and accessory=v_accessory and
    station_id=v_station_id and substation_id=v_substation_id and image_id=v_image_id;
    -- remove all the cell rows for the draft, they will be created anew
    delete from qcis_draft_cells where draft_id = v_id;
      BEGIN
      select pixel_width, pixel_height into v_width, v_height from images
      where images_id = v_image_id;
      EXCEPTION
        WHEN NO_DATA_FOUND THEN
        v_height := 720;
        v_width := 520;
      END;
    -- the first part of the href for the image is stored in the keyword table and put into v_url_1 for use later
      BEGIN
      select keyword_value into v_url_1 from qcis_keywords
      where keyword_type = 'Control' and keyword_code = 'URL_PATH';
      EXCEPTION
        WHEN NO_DATA_FOUND THEN
        v_url_1 := 'http://xxx.xxx.com:8000/apex40/f?p=';
      END; 
    -- construct the first three lines of the div tag 
      v_html := '<div style="text-align:center; width:'||v_width||'px; margin-left:auto; margin-right:auto;">';
      v_html := v_html || chr(10) || '<img id="ImageMap" src="download_image?p_id='||v_image_id||'" usemap="#ImageMap" border="0" width="'||v_width||'" height="'||v_height||'" alt="" />';
      v_html := v_html || chr(10) || '<map id="_ImageMap" name="ImageMap">';
    -- subtract the ending inset amounts from the image dimensions
      v_width := v_width - v_wend;
      v_height := v_height - v_hend;
    -- calculate the increment for each cell and subtract the starting inset amounts
      v_winc := floor((v_width - v_wstart) / v_wmax);
      v_hinc := floor((v_height - v_hstart) / v_hmax);
    -- there are two main loops, one for the columns, one for the rows
    -- one loop is inside the other, which helps to build the cells in logical order and helps with the naming of the cells 
      loop
    -- if this is the first row (count = 0) and they have inset values we need to adust the first x y values to something other than zero 
    if ((v_wstart != 0) and (v_wcount = 0)) then v_w1 := v_wstart; end if;
    if ((v_hstart != 0) and (v_hcount = 0)) then v_h1 := v_hstart; end if;
    if ((v_wstart != 0) and (v_wcount = 0)) then v_w2 := v_wstart; end if;
    if ((v_hstart != 0) and (v_hcount = 0)) then v_h2 := v_hstart; end if;
    v_wcount := v_wcount + 1;
    v_w2 := v_w2 + v_winc;
    -- checking to see if this is the last row and whether they want the grid to go to the end or have all cells the same size which may leave whitespace
             if (v_wcount = v_wmax) and (v_whitespace = 'Y') then v_w2 := v_width - 2; end if;
      v_cell_row := 0;
      v_cell_col := v_cell_col +1;
             loop
             v_hcount := v_hcount + 1;           
             v_h2 := v_h2 + v_hinc;
    -- checking to see if this is the last row and whether they want the grid to go to the end or have all cells the same size which may leave whitespace
                    if (v_hcount = v_hmax) and (v_whitespace = 'Y') then v_h2 := v_height - 2; end if;
             v_cell_row := v_cell_row + 1;
             -- put it all together and construct the line for the area shape tag
             v_html := v_html || chr(10) || '<area shape="rect" coords="'
             ||v_w1||','||v_h1||','||v_w2||','||v_h2||
             '" href="'||v_url_1|| '" alt="'||v_cell_col||'-'||v_cell_row||'" title="'||v_cell_col||'-'||v_cell_row||'"    />';
             v_cell_title := v_cell_col||'-'||v_cell_row;
                insert into DRAFT_CELLS (DRAFT_ID, CELL_TITLE) values(v_id, v_cell_title);          
             v_h1 := v_h1 + v_hinc;
                exit when v_hcount = v_hmax;
            end loop;
      v_hcount := 0;
      v_h1 := 0;
      v_h2 := 0;
      v_w1 := v_w1 + v_winc;
         exit when v_wcount = v_wmax;     
      end loop;
      v_html := v_html || chr(10) || '</div>';
    update IM_TEMPLATE_DRAFT set imagemap_html = v_html
    where header_id = v_id;  
    END create_grid;Edited by: cloaked on Nov 7, 2011 4:45 AM

    For "Application Express 4.2.1.00.08" i created such good solution.
    I downloaded freeware plugin "Enkitec Clob Load Plug-in Version: 1.0.0 - APEX Version: 4.2.0" from there:
    http://www.enkitec.com/products/plugins/clob-load/help
    Then i followed plugin installation steps and created a APEX page where i added an item of type "Rich Text Editor".
    I found the plugin crashes when my database CLOB field is empty, also crashed when i tried to save down empty value to database.
    I changed Plugin code a little, and now everything works as needed, i can save down larga data, and also empty data.
    1. In Apex open plugin "Enkitec CLOB Load".
    2. Navigate to "Source-->PL/SQL Code" where is text area with plugin source code.
    3. there you have such code:
    FUNCTION enkitec_clob_load_render (
       p_dynamic_action IN APEX_PLUGIN.T_DYNAMIC_ACTION,
       p_plugin         IN APEX_PLUGIN.T_PLUGIN
       RETURN APEX_PLUGIN.T_DYNAMIC_ACTION_RENDER_RESULT
    IS
       l_retval           APEX_PLUGIN.T_DYNAMIC_ACTION_RENDER_RESULT;
       l_show_modal       VARCHAR2(1) := p_plugin.attribute_01;
       l_dialog_title     VARCHAR2(4000) := NVL(p_plugin.attribute_02, 'Please wait...');
       l_loading_img_type VARCHAR2(30) := p_plugin.attribute_03;
       l_loading_img_c    VARCHAR2(4000) := p_plugin.attribute_04;
       l_action           VARCHAR2(10) := NVL(p_dynamic_action.attribute_01, 'RENDER');
       l_change_only      VARCHAR2(1) := NVL(p_dynamic_action.attribute_06, 'Y');
       l_make_blocking    VARCHAR2(1) := NVL(p_dynamic_action.attribute_07, 'Y');
       l_loading_img_src  VARCHAR2(32767);
       l_crlf             VARCHAR2(2) := CHR(13)||CHR(10);
       l_js_function      VARCHAR2(32767);
       l_onload_code      VARCHAR2(32767);
    BEGIN
       IF apex_application.g_debug
       THEN
          apex_plugin_util.debug_dynamic_action(
             p_plugin         => p_plugin,
             p_dynamic_action => p_dynamic_action
       END IF;
       IF l_loading_img_type = 'DEFAULT'
       THEN
          l_loading_img_src := p_plugin.file_prefix || 'enkitec-loading.gif';
       ELSE
          l_loading_img_src := REPLACE(l_loading_img_c, '#IMAGE_PREFIX#', apex_application.g_image_prefix);
          l_loading_img_src := REPLACE(l_loading_img_src, '#PLUGIN_PREFIX#', p_plugin.file_prefix);
       END IF;
       apex_css.add(
          p_css => '.clob-load-dialog .ui-dialog-titlebar-close {display: none;}',
          p_key => 'clob-load-hide-modal-close'
       apex_javascript.add_library(
          p_name      => 'enkitec-clob-load.min',
          p_directory => p_plugin.file_prefix,
          p_version   => NULL
       l_onload_code :=
          'apex.jQuery(document).clob_load({'|| l_crlf ||
          '   showModal: "' || l_show_modal ||'",'|| l_crlf ||
          '   dialogTitle: "' || l_dialog_title ||'",'|| l_crlf ||
          '   loadingImageSrc: "' || l_loading_img_src ||'",'|| l_crlf ||
          '   pluginFilePrefix: "' || p_plugin.file_prefix || '",' || l_crlf ||
          '   apexImagePrefix: "' || apex_application.g_image_prefix || ',"' || l_crlf ||
       apex_javascript.add_onload_code(
          p_code => l_onload_code
       IF l_action = 'RENDER'
       THEN
          l_js_function :=
             'function(){'|| l_crlf ||
             '   apex.jQuery(document).clob_load("renderClob", {' || l_crlf ||
             '      $elmt: this.affectedElements.eq(0),' || l_crlf ||
             '      ajaxIdentifier: "' || apex_plugin.get_ajax_identifier() || '"' || l_crlf ||
             '   });'|| l_crlf ||
       ELSE
          l_js_function :=
             'function(){'|| l_crlf ||
             '   apex.jQuery(document).clob_load("submitClob", {' || l_crlf ||
             '      $elmt: this.affectedElements.eq(0),' || l_crlf ||
             '      ajaxIdentifier: "' || apex_plugin.get_ajax_identifier() || '",' || l_crlf ||
             '      changeOnly: "' || l_change_only || '",' || l_crlf ||
             '      makeBlocking: "' || l_make_blocking || '"' || l_crlf ||
             '   });'|| l_crlf ||
       END IF;
       l_retval.javascript_function := l_js_function;
       RETURN l_retval;
    END enkitec_clob_load_render;
    FUNCTION enkitec_clob_load_ajax (
       p_dynamic_action IN APEX_PLUGIN.T_DYNAMIC_ACTION,
       p_plugin         IN APEX_PLUGIN.T_PLUGIN
        RETURN APEX_PLUGIN.T_DYNAMIC_ACTION_AJAX_RESULT
    IS
       l_retval                   APEX_PLUGIN.T_DYNAMIC_ACTION_AJAX_RESULT;
       l_ajax_function            VARCHAR2(32767) := apex_application.g_x01;
       l_source                   VARCHAR2(20) := NVL(p_dynamic_action.attribute_02, 'COLLECTION');
       l_render_collection_name   VARCHAR2(255) := p_dynamic_action.attribute_03;
       l_query                    VARCHAR2(32767) := p_dynamic_action.attribute_04;
       l_submit_collection_name   VARCHAR2(255) := p_dynamic_action.attribute_05;
       l_column_value_list        APEX_PLUGIN_UTIL.T_COLUMN_VALUE_LIST2;    
       l_clob_text                CLOB := EMPTY_CLOB();
       l_token                    VARCHAR2(32000);
       l_chunk_size               NUMBER := 4000;
    BEGIN
       IF l_ajax_function = 'RENDER_CLOB'
       THEN
          IF l_source = 'COLLECTION'
          THEN
             IF apex_collection.collection_exists(l_render_collection_name)
             THEN
                SELECT clob001
                INTO l_clob_text
                FROM apex_collections
                WHERE collection_name = l_render_collection_name
                   AND seq_id = 1;
             END IF;
          ELSE --must be SQL_QUERY
             BEGIN
                l_column_value_list := apex_plugin_util.get_data2(
                   p_sql_statement  => l_query,
                   p_min_columns    => 1,
                   p_max_columns    => 1,
                   p_component_name => p_dynamic_action.action,
                   p_first_row      => 1,
                   p_max_rows       => 1
             EXCEPTION
                WHEN NO_DATA_FOUND
                THEN
                   NULL;
             END;
             IF l_column_value_list.exists(1)
                AND l_column_value_list(1).value_list.exists(1)
             THEN
                l_clob_text := l_column_value_list(1).value_list(1).clob_value;
             END IF;
          END IF;
          FOR i IN 0 .. FLOOR(LENGTH(l_clob_text)/l_chunk_size)
          LOOP 
             sys.htp.prn(substr(l_clob_text, i * l_chunk_size + 1, l_chunk_size)); 
          END LOOP;
       ELSE --must be SUBMIT_CLOB
          dbms_lob.createtemporary(l_clob_text, false, dbms_lob.session);
          FOR i IN 1..apex_application.g_f01.count
          LOOP
             l_token := wwv_flow.g_f01(i);
             dbms_lob.writeappend(l_clob_text, length(l_token), l_token);
          END LOOP;
          apex_collection.create_or_truncate_collection(
             p_collection_name => l_submit_collection_name
          apex_collection.add_member(
             p_collection_name => l_submit_collection_name,
             p_clob001         => l_clob_text
       END IF;
       RETURN l_retval;
    END enkitec_clob_load_ajax;4. Change this code to this code:
    FUNCTION enkitec_clob_load_render (
       p_dynamic_action IN APEX_PLUGIN.T_DYNAMIC_ACTION,
       p_plugin         IN APEX_PLUGIN.T_PLUGIN
       RETURN APEX_PLUGIN.T_DYNAMIC_ACTION_RENDER_RESULT
    IS
       l_retval           APEX_PLUGIN.T_DYNAMIC_ACTION_RENDER_RESULT;
       l_show_modal       VARCHAR2(1) := p_plugin.attribute_01;
       l_dialog_title     VARCHAR2(4000) := NVL(p_plugin.attribute_02, 'Please wait...');
       l_loading_img_type VARCHAR2(30) := p_plugin.attribute_03;
       l_loading_img_c    VARCHAR2(4000) := p_plugin.attribute_04;
       l_action           VARCHAR2(10) := NVL(p_dynamic_action.attribute_01, 'RENDER');
       l_change_only      VARCHAR2(1) := NVL(p_dynamic_action.attribute_06, 'Y');
       l_make_blocking    VARCHAR2(1) := NVL(p_dynamic_action.attribute_07, 'Y');
       l_loading_img_src  VARCHAR2(32767);
       l_crlf             VARCHAR2(2) := CHR(13)||CHR(10);
       l_js_function      VARCHAR2(32767);
       l_onload_code      VARCHAR2(32767);
    BEGIN
       IF apex_application.g_debug
       THEN
          apex_plugin_util.debug_dynamic_action(
             p_plugin         => p_plugin,
             p_dynamic_action => p_dynamic_action
       END IF;
       IF l_loading_img_type = 'DEFAULT'
       THEN
          l_loading_img_src := p_plugin.file_prefix || 'enkitec-loading.gif';
       ELSE
          l_loading_img_src := REPLACE(l_loading_img_c, '#IMAGE_PREFIX#', apex_application.g_image_prefix);
          l_loading_img_src := REPLACE(l_loading_img_src, '#PLUGIN_PREFIX#', p_plugin.file_prefix);
       END IF;
       apex_css.add(
          p_css => '.clob-load-dialog .ui-dialog-titlebar-close {display: none;}',
          p_key => 'clob-load-hide-modal-close'
       apex_javascript.add_library(
          p_name      => 'enkitec-clob-load.min',
          p_directory => p_plugin.file_prefix,
          p_version   => NULL
       l_onload_code :=
          'apex.jQuery(document).clob_load({'|| l_crlf ||
          '   showModal: "' || l_show_modal ||'",'|| l_crlf ||
          '   dialogTitle: "' || l_dialog_title ||'",'|| l_crlf ||
          '   loadingImageSrc: "' || l_loading_img_src ||'",'|| l_crlf ||
          '   pluginFilePrefix: "' || p_plugin.file_prefix || '",' || l_crlf ||
          '   apexImagePrefix: "' || apex_application.g_image_prefix || ',"' || l_crlf ||
       apex_javascript.add_onload_code(
          p_code => l_onload_code
       IF l_action = 'RENDER'
       THEN
          l_js_function :=
             'function(){'|| l_crlf ||
             '   apex.jQuery(document).clob_load("renderClob", {' || l_crlf ||
             '      $elmt: this.affectedElements.eq(0),' || l_crlf ||
             '      ajaxIdentifier: "' || apex_plugin.get_ajax_identifier() || '"' || l_crlf ||
             '   });'|| l_crlf ||
       ELSE
          l_js_function :=
             'function(){'|| l_crlf ||
             '   apex.jQuery(document).clob_load("submitClob", {' || l_crlf ||
             '      $elmt: this.affectedElements.eq(0),' || l_crlf ||
             '      ajaxIdentifier: "' || apex_plugin.get_ajax_identifier() || '",' || l_crlf ||
             '      changeOnly: "' || l_change_only || '",' || l_crlf ||
             '      makeBlocking: "' || l_make_blocking || '"' || l_crlf ||
             '   });'|| l_crlf ||
       END IF;
       l_retval.javascript_function := l_js_function;
       RETURN l_retval;
    END enkitec_clob_load_render;
    FUNCTION enkitec_clob_load_ajax (
       p_dynamic_action IN APEX_PLUGIN.T_DYNAMIC_ACTION,
       p_plugin         IN APEX_PLUGIN.T_PLUGIN
        RETURN APEX_PLUGIN.T_DYNAMIC_ACTION_AJAX_RESULT
    IS
       l_retval                   APEX_PLUGIN.T_DYNAMIC_ACTION_AJAX_RESULT;
       l_ajax_function            VARCHAR2(32767) := apex_application.g_x01;
       l_source                   VARCHAR2(20) := NVL(p_dynamic_action.attribute_02, 'COLLECTION');
       l_render_collection_name   VARCHAR2(255) := p_dynamic_action.attribute_03;
       l_query                    VARCHAR2(32767) := p_dynamic_action.attribute_04;
       l_submit_collection_name   VARCHAR2(255) := p_dynamic_action.attribute_05;
       l_column_value_list        APEX_PLUGIN_UTIL.T_COLUMN_VALUE_LIST2;    
       l_clob_text                CLOB := EMPTY_CLOB();
       l_token                    VARCHAR2(32000);
       l_chunk_size               NUMBER := 4000;
    BEGIN
       IF l_ajax_function = 'RENDER_CLOB'
       THEN
          IF l_source = 'COLLECTION'
          THEN
             IF apex_collection.collection_exists(l_render_collection_name)
             THEN
                SELECT clob001
                INTO l_clob_text
                FROM apex_collections
                WHERE collection_name = l_render_collection_name
                   AND seq_id = 1;
             END IF;
          ELSE --must be SQL_QUERY
             BEGIN
                l_column_value_list := apex_plugin_util.get_data2(
                   p_sql_statement  => l_query,
                   p_min_columns    => 1,
                   p_max_columns    => 1,
                   p_component_name => p_dynamic_action.action,
                   p_first_row      => 1,
                   p_max_rows       => 1
             EXCEPTION
                WHEN NO_DATA_FOUND
                THEN
                   NULL;
             END;
             IF l_column_value_list.exists(1)
                AND l_column_value_list(1).value_list.exists(1)
             THEN
                l_clob_text := l_column_value_list(1).value_list(1).clob_value;
             END IF;
          END IF;
          FOR i IN 0 .. FLOOR(NVL(LENGTH(l_clob_text)/l_chunk_size,0))
          LOOP 
             sys.htp.prn(substr(l_clob_text, i * l_chunk_size + 1, l_chunk_size)); 
          END LOOP;
       ELSE --must be SUBMIT_CLOB
          dbms_lob.createtemporary(l_clob_text, false, dbms_lob.session);
          FOR i IN 1..apex_application.g_f01.count
          LOOP
             l_token := wwv_flow.g_f01(i);
             if NVL(length(l_token),0) > 0 Then
                dbms_lob.writeappend(l_clob_text, length(l_token), l_token);
             end if;
          END LOOP;
          apex_collection.create_or_truncate_collection(
             p_collection_name => l_submit_collection_name
          apex_collection.add_member(
             p_collection_name => l_submit_collection_name,
             p_clob001         => l_clob_text
       END IF;
       RETURN l_retval;
    END enkitec_clob_load_ajax;5. As you see only 2 places of plugin had to be fixed, when you compare previous 2 steps:
    FOR i IN 0 .. FLOOR(LENGTH(l_clob_text)/l_chunk_size)
          LOOP 
             sys.htp.prn(substr(l_clob_text, i * l_chunk_size + 1, l_chunk_size)); 
          END LOOP;-->
    FOR i IN 0 .. FLOOR(NVL(LENGTH(l_clob_text)/l_chunk_size,0))
          LOOP 
             sys.htp.prn(substr(l_clob_text, i * l_chunk_size + 1, l_chunk_size)); 
          END LOOP;And
    FOR i IN 1..apex_application.g_f01.count
          LOOP
             l_token := wwv_flow.g_f01(i);
             dbms_lob.writeappend(l_clob_text, length(l_token), l_token);
          END LOOP;-->
    FOR i IN 1..apex_application.g_f01.count
          LOOP
             l_token := wwv_flow.g_f01(i);
             if NVL(length(l_token),0) > 0 Then
                dbms_lob.writeappend(l_clob_text, length(l_token), l_token);
             end if;
          END LOOP;This way seems to be best way to handle APEX CLOBS today, using that plugin, and a little fix.

  • How to set up SSO between e-portal employee node & ebill customer node?

    We have a requirement to set up SSO between e-portal employee node & ebill customer node.
    I am told that sso is possible only between 2 employee nodes.
    Please advise.

    Not sure I understand which part is failing.
    Is it the C program calling your packaged function? Or does the error occur in the PL/SQL code, in which case you should be able to pinpoint where it's wrong?
    A few comments :
    1) Using DOM to build XML out of relational data? What for? Use SQL/XML functions.
    2) Giving sample data is usually great, but it's not useful here since we can't run your code. We're missing the base tables.
    3) This is wrong :
    vStrSqlQuery := 'SELECT * FROM ' || vTblName                     || ' WHERE record_update_tms <= TO_DATE(''' || TO_CHAR(vLastPubTms, 'MM/DD/YYYY HH24:MI:SS') || ''', ''MM/DD/YYYY HH24:MI:SS'') ' ;
    A bind variable should be used here for the date.
    4) This is wrong :
    elmt_value := xmldom.createTextNode (doc, l_clob(1));
    createTextNode does not support CLOB so it will fail as soon as the CLOB you're trying to pass exceeds 32k.
    Maybe that's the problem you're referring to?
    5) This is most wrong :
         l_clob(1):=REPLACE(l_clob(1),'&lt;?xml version=&quot;1.0&quot;?&gt;', NULL); 
         l_clob(1):=REPLACE(l_clob(1),'&lt;', '<'); 
         l_clob(1):=REPLACE(l_clob(1),'&gt;', '>'); 
    I understand what you're trying to do but it's not the correct way.
    You're trying to convert a text() node representing XML in escaped form back to XML content.
    The problem is that there are other things to take care of besides just '&lt;' and '&gt;'.
    If you want to insert an XML node into an existing document, treat that as an XML node, not as a string.
    Anyway,
    Anyone that can help me to find out the required magic number
    That would be a bad idea. Fix what needs to be fixed.
    And please clearly state which part is failing : the C program or the PL/SQL code?
    I'd vote for PL/SQL, as pointed out in [4].

  • Query XML(CLOB) datatype

    Hello,
    I am new to XML and have been trying this for few days and get no luck ...
    First, I have an Excel file, which contains a list of bills for customers. It is a sample file to test my application.
    In the future, my application will receive data of XML-datatype, so my job here is to import this Excel file into my Oracle database 11gr2, then transform it to XML datatype one.
    I did import it by using Oracle SQL Developer and nicely stored it in a table called so_lieu.
    After that, I run the following code to convert the table data to XML datatype:
    CREATE TABLE xmlDoc(temp CLOB);
    DECLARE
      qryCtx DBMS_XMLGEN.ctxHandle;
      temp CLOB;
    BEGIN
      qryCtx := DBMS_XMLGEN.newContext('SELECT * FROM huy.so_lieu');
      -- Set the row header to be bill
      DBMS_XMLGEN.setRowTag(qryCtx, 'bill');
      -- Get the result
      temp := DBMS_XMLGEN.getXML(qryCtx);
      INSERT INTO xmlDoc VALUES(temp);
      --Close context
      DBMS_XMLGEN.closeContext(qryCtx);
    END;
    It is a success:
    table XMLDOC created.
    anonymous block completed
    When I run: SELECT * from xmlDoc; I can get a data of XML-datatype as following:
    <?xml version="1.0"?>
    <ROWSET>
    <bill>
      <MA_CQTT>5335</MA_CQTT>
      <ACCOUNT>P482668</ACCOUNT>
      <TEN_CQTT>Công ty TNHH FrieslandCampina Việt Nam</TEN_CQTT>
      <DIACHI>phường Bình Hòa, Thị xã Thuận An, Bình Dương</DIACHI>
      <MS_THUE>3700229344-   -</MS_THUE>
      <SDT>754422 ext 333</SDT>
      <LOAI_DV>48</LOAI_DV>
      <TEN>Mail - SMD</TEN>
      <CUOC_DV>0</CUOC_DV>
      <DC>0</DC>
      <CUOC_TBSD>0</CUOC_TBSD>
      <TRUY_THU>0</TRUY_THU>
      <TONG_TIEN>22254545</TONG_TIEN>
      <VAT>2225455</VAT>
    </bill>
    <bill>
      <MA_CQTT>90255</MA_CQTT>
      <ACCOUNT>P0421100</ACCOUNT>
      <TEN_CQTT>VPĐD HOME MERIDIAN INTERNATIONAL,INC TạI TP.HCM</TEN_CQTT>
      <DIACHI>Tầng trệt, Block C, Cao ốc An Khang, P. An Phú, Q.2, TP.HCM</DIACHI>
      <MS_THUE>0302199864-   -</MS_THUE>
      <SDT>838228511</SDT>
      <FAX>838293764</FAX>
      <LOAI_DV>7</LOAI_DV>
      <TEN>Internet trực tiếp</TEN>
      <CUOC_DV>0</CUOC_DV>
      <DC>0</DC>
      <CUOC_TBSD>35446000</CUOC_TBSD>
      <TRUY_THU>0</TRUY_THU>
      <TONG_TIEN>35446000</TONG_TIEN>
      <VAT>3544600</VAT>
    </bill>
    </ROWSET>
    Then I try to select/query the XML elements inside that XML data (to parse them into another tables) but cannot. I tried:
    SELECT XMLQuery('
        for $x in ora:view("xmlDoc")/ROW
           return $x/TEMP/ROWSET/bill/MA_CQTT
    ' RETURNING CONTENT) FROM DUAL;
    It gave errors
    ORA-19276: XPST0005 - XPath step specifies an invalid element/attribute name: (ROWSET)
    19276. 00000 -  "XP0005 - XPath step specifies an invalid element/attribute name: (%s)"
    *Cause:    The XPath step specified invalid element or attribute name that did not match any nodes according to the input XML schema or structure.
    *Action:   Correct the element or attribute name as the name may be mis-spelled.
    I read several threads and think that maybe my ROWSET element is not XML anymore. Thus, cannot select using XPath. How can I fix it?
    Thank you in advance,
    Huy Do.
    PS: I tried using XMLTABLE as below:
    SELECT x2.*
      from XMLDOC h,
        XMLTABLE(
          '//ROWSET/bill'
          PASSING xmltype(h.temp)
          COLUMNS ma_cqtt  varchar(20) path 'ma_cqtt'
          ) x2
    The query gave me a table of 2566 row of "ma_cqtt" but their value are all "null" (excel file has 2566 rows of record)
    Message was edited by: 2716502

    Thank you Odie I tried:
    INSERT INTO DM_TABLE (ma_cqtt, account, thang_ps)
        select x.ma_cqtt
             , x.account
             , thangps as thang
    Of course it returned an error, how silly of me to complicate thing like that
    And I have one more question about the speed to parse a xml data. Please, help me with it.
    In my code, I usually store xml data as a row in a temporary table (table mau_so_lieu). Then when doing parsing, I call the xml data from that table and the processing time is usually ~0.5s only. The code is like below:
    INSERT INTO mau_so_lieu VALUES(xmlData);
    INSERT INTO DM (                         
                                ma_kh, account, thang_ps)
        select x.ma_kh, x.account, thang
          from mau_so_lieu m, xmltable
              ('//Bao_cuoc'
                passing m.BILL
                columns
                   ma_kh varchar2(20) path '@ma_cqtt'
                  , account varchar2(20) path '@account'
              ) x;
    But one of my senior (SQL server expert) suggested to store xml data in a variable (xmlData XMLType) as he thought the processing time will be even shorter, as well as no temporary table needed (no trash left which need to be cleaned later). I tried that but somehow the processing time is > 5s with the code as below:
    INSERT INTO DM (                         
                                ma_kh, account, thang_ps)
        select x.ma_kh, x.account, thang
          from xmltable
              ('//Bao_cuoc'
                passing xmlData
                columns
                   ma_kh varchar2(20) path '@ma_cqtt'
                  , account varchar2(20) path '@account'
              ) x;
    Could you tell me why the processing time are so different? Is it because of the default RAM of Oracle XE 11g is too small to process?
    Thank you very much,
    Huy Do.

Maybe you are looking for