如何使用DBMS_XMLSave在ORACLE批量xml插入中设置自动增量字段值

时间:2015-04-17 11:53:56

标签: xml oracle bulk

我使用DBMS_XMLSave在oracle中插入bulk xml。我得到以下异常ORA-20001:43 ORA-29532:Java调用因未捕获的Java异常而终止:oracle.xml.sql.OracleXMLSQLException:'java.sql.BatchUpdateException:ORA-01400:无法插入NULL(“ORA11G_41_DEVUPD”。 “LGEX”。 “REC_IDENTITY”)。

我的桌子是

create table LGEX (
LOGDATE         DATE            NULL,
LOGLEN          numeric (10,0)  NULL,
LOGTIME         char(8)     NULL,
WORKSTATION     char(32)    NULL,
NETID           char(32)    NULL,
LOGHDR          char(10)    NULL,
BR              char(2)     NULL,
BRPROCDATE      DATE        NULL,
PCID            char(6)     NULL,
USERID          char(4)     NULL,
TASK            CHAR(20)        NULL,
EVENT           varchar2(100)   NULL,
LOGMESSAGE      NCLOB       NULL,
REC_IDENTITY        NUMERIC (15, 0) NOT NULL,
CONSTRAINT LGEXPK PRIMARY KEY (REC_IDENTITY))
/
CREATE SEQUENCE LGEX_REC_IDENTITY_SEQ INCREMENT BY 1 START WITH 2
/

我写的SP是

create or replace procedure SP_ADDREC_LOG_OUTPUT_BULK(XMLSTRING IN clob) is
  insCtx DBMS_XMLSave.ctxType;
  doc clob;
  rows number;     
  SQL_DELQUERY VARCHAR2(4000);
  SQL_UPDATEQUERY VARCHAR2(4000); 
  C_DELIM CHAR(1) DEFAULT CHR(28);
    E_ERROROCCURRED EXCEPTION;
    PRAGMA EXCEPTION_INIT(E_ERROROCCURRED, -20001);
begin   
        insCtx := DBMS_XMLSave.newContext('LOG_OUTPUT'); -- get the save context..!
         DBMS_XMLSave.setRowTag(insctx,'LogEntry');

         DBMS_XMLSave.setDateFormat(insctx,'MM/dd/yyyy HH:MM:SS');
         DBMS_XMLSave.clearUpdateColumnList(insCtx); -- clear the update settings

         -- set the columns to be updated as a list of values..
         DBMS_XMLSave.setUpdateColumn(insCtx,'USERNAME'); 
         DBMS_XMLSave.setUpdateColumn(insCtx,'LOG_DATE');
         DBMS_XMLSave.setUpdatecolumn(insCtx,'CATEGORY');
         DBMS_XMLSave.setUpdatecolumn(insCtx,'TRANSACTION_STREAM');
         DBMS_XMLSave.setUpdatecolumn(insCtx,'FUNCTION_CODE');
         DBMS_XMLSave.setUpdatecolumn(insCtx,'SYSTEM_NAME');
         DBMS_XMLSave.setUpdatecolumn(insCtx,'MESSAGE');
         DBMS_XMLSave.setUpdatecolumn(insCtx,'MESSAGE_TYPE');
         DBMS_XMLSave.setUpdatecolumn(insCtx,'SESSION_ID');
         DBMS_XMLSave.setUpdatecolumn(insCtx,'THREAD_ID');
         DBMS_XMLSave.setUpdatecolumn(insCtx,'SR_ID');
         DBMS_XMLSave.setUpdatecolumn(insCtx,'TRACE_TOKEN');
         DBMS_XMLSave.setUpdatecolumn(insCtx,'OWNER');
         DBMS_XMLSave.setUpdatecolumn(insCtx,'APP_SRV_NAME');
         DBMS_XMLSave.setUpdatecolumn(insCtx,'APP_SRV_IP');
         DBMS_XMLSave.setUpdatecolumn(insCtx,'BR');
         DBMS_XMLSave.setUpdatecolumn(insCtx,'SEQUENCE_NUMBER');
         DBMS_XMLSave.setUpdatecolumn(insCtx,'SEQUENCE_LEVEL');
         DBMS_XMLSave.setUpdatecolumn(insCtx,'TRANSACTION_ID');
         DBMS_XMLSave.setUpdatecolumn(insCtx,'LSTMNTDATE_DEF_TIME');

         -- Now insert the doc. 
         rows := DBMS_XMLSave.insertXML(insCtx, xmlString); 
         DBMS_XMLSave.closeContext(insCtx);               

  EXCEPTION
    WHEN E_ERROROCCURRED THEN
        RAISE_APPLICATION_ERROR(SQLCODE, SQLERRM);
    WHEN OTHERS THEN
        RAISE_APPLICATION_ERROR(-20001, '43' || C_DELIM || RTRIM(SQLERRM) || C_DELIM || RTRIM(DBMS_UTILITY.FORMAT_CALL_STACK));
end;
/


I am looking for fast solution.

0 个答案:

没有答案