2012-10-08 10 views
0

Oracle 데이터베이스를 백엔드에서 사용하는 응용 프로그램을 상속 받았습니다. 데이터베이스는 원래 Oracle의 정식 버전을 사용했지만 Oracle XE로 옮겼습니다. Oracle XE는 Oracle XML SQL Utility (DBMS_XMLSave 포함)를 지원하지 않거나, 적어도 설치 방법을 파악할 수 없었습니다.Oracle 저장 프로 시저를 DBMS_XMLSave에서 DBMS_XMLStore로 변환

처럼 DBMS_XMLQUERY, DBMS_XMLSAVE가 자바로 구현되고, 따라서이 오라클 데이터베이스 Express Edition을 지원 아니에요 :이 링크 (http://ellebaek.wordpress.com/2011/01/27/converting-between-oracle-data-and-xml/)에 따르면

. 데이터베이스에

저장 프로는 DBMS_XMLSave를 사용하지만,이 링크 (https://forums.oracle.com/forums/thread.jspa?threadID=530048)에서이 DBMS_XMLSave가 DBMS_XMLStore로 대체 된 것으로 나타납니다

DBMS_XMLSTORE PL/SQL 패키지는 오라클 데이터베이스 10g에 도입 된

릴리스 1.이 패키지는 XML 문서의 내용을 기반으로 데이터베이스 내의 관계형 또는 오브젝트 테이블에 대해 DML 조작을 수행합니다.

Oracle Database 10g 이전에는이 ​​기능이 DBMS_XMLSAVE라는 다른 PL/SQL 패키지에 존재했습니다. 그러나 나는 몇 가지 문제 라인 왼쪽 된,

CREATE OR REPLACE PUBLIC SYNONYM DBMS_XMLSAVE FOR DBMS_XMLSTORE; 
GRANT EXECUTE ON DBMS_XMLSAVE TO PUBLIC; 
이 오류의 큰 부분을 수정했다

:

DBMS_XMLSave.setDateFormat(v_insCtx, 'MM/dd/yyyy'); 
DBMS_XMLSave.setBatchSize(v_updCtx, -1); 
DBMS_XMLSave.setDateFormat(v_updCtx, 'MM/dd/yyyy'); 

DBMS_XMLStore가하는

나는 링크에서 솔루션을 시도 이러한 방법을 지원하지 않습니다. 주위를 파고 나는 setDateFormat을 해결하는 방법을 찾았다 고 생각합니다. 이 링크 (http://ellebaek.wordpress.com/2011/01/27/converting-between-oracle-data-and-xml/)에 따르면 DBMS_XMLStore는 날짜/시간 값에 NLS 설정을 사용합니다. 이 링크 (http://www.tiplib.com/231/nls-parameter-session-logon-trigger)는 NLS 설정은 다음과 같이 저장 프로 시저에서 변경 될 수 있음을 지적했다 :

-DBMS_XMLSave.setDateFormat(v_insCtx, 'MM/dd/yyyy'); -- remove 
+DBMS_SESSION.SET_NLS('NLS_DATE_FORMAT','MM/dd/yyyy'); -- insert 

내가했다 :

BEGIN 
    DBMS_SESSION.SET_NLS('NLS_DATE_FORMAT','YYYYMMDD'); 
    COMMIT; 
END; 

그래서 나는이 같은 setDateFormat 라인을 대체 할 것으로 기대하고있다

setBatchSize를 대체 할 수 없습니다. 내가 올바른 방법으로이 문제를 접근

  1. 암, 또는 더 나은 방법이있다 :

    그래서 내 질문은?

  2. DBMS_XMLSave.setDateFormat (v_insCtx, 'MM/DD/YYYY') 윌 -> DBMS_SESSION.SET_NLS ('NLS_DATE_FORMAT을', 'MM/DD/YYYY')가 변경 작업?

  3. setBatchSize를 대체 할 수 있습니까? setBatchSize를 대체해야합니까? 나는 그것을 시도하고 말해 그들에게 말할 것입니다,하지만 난 현재 컴파일하는 코드를 얻을 수 없다 내가 올바르게 작동하는 기준이없는 이상 누군가가 질문이 같은 질문을 일반적으로 경우

.나는 문제점 선을 제거 할 수 있었고 아마도 결과가 약간 나왔지만 결과가 맞는지 확실하지 않을 것이다. 문제 라인을 제거하고 결과를 확인하려고하면 여기에서 나의 접근 방식이 될 것입니다. 당신의 도움을

procedure insert_xml(p_xmlDoc in clob, p_tableName in varchar2) is 
     v_insCtx DBMS_XMLSave.ctxType; 
     v_rows number; 
    begin 
     v_insCtx := DBMS_XMLSave.newContext(p_tableName); -- get the context handle 
     DBMS_XMLSave.setDateFormat(v_insCtx, 'MM/dd/yyyy'); -- set date format 
     v_rows := DBMS_XMLSave.insertXML(v_insCtx, p_xmlDoc); -- this inserts the document 
     DBMS_XMLSave.closeContext(v_insCtx); -- this closes the handle 
    exception 
     when OTHERS then 
     raise_application_error(-20001,'An error was encountered. - '||SQLCODE||' -ERROR- '||SQLERRM); 
    end insert_xml; 

    procedure update_xml(p_xmlDoc in clob, p_tableName in varchar2, p_key in varchar2) is 
      v_updCtx DBMS_XMLSave.ctxType; 
      v_rows number; 
     begin 
      v_updCtx := DBMS_XMLSave.newContext(p_tableName); -- get the context 
      DBMS_XMLSave.setBatchSize(v_updCtx, -1); 
      DBMS_XMLSave.setDateFormat(v_updCtx, 'MM/dd/yyyy'); -- set date format 
      DBMS_XMLSave.clearUpdateColumnList(v_updCtx); -- clear the update settings.. 
      DBMS_XMLSave.setKeyColumn(v_updCtx, p_key); -- set EMPNO as key column 
      v_rows := DBMS_XMLSave.updateXML(v_updCtx, p_xmlDoc); -- update the table. 
      DBMS_XMLSave.closeContext(v_updCtx); -- close the context..! 
     exception 
     when OTHERS then 
      raise_application_error(-20001,'An error was encountered. - '||SQLCODE||' -ERROR- '||SQLERRM); 
     end update_xml; 

감사를 다음과 같이

원래의 코드입니다.

답변

0

나는 준 질문에 답했습니다. 내가했을 때 : 내가 발견에 대해 파고 후

ORA-31011: XML parsing failed 
ORA-19202: Error occurred in XML processing 
LPX-00222: error received from SAX callback function 
ORA-01843: not a valid month 

:

DBMS_SESSION.SET_NLS('NLS_DATE_FORMAT','MM/DD/YYYY'); 

는 나는 이러한 오류를 얻었다 발견이 날짜 처리가 불평하지 얻을 나타났다

EXECUTE IMMEDIATE 'ALTER SESSION SET NLS_DATE_FORMAT = "MM/DD/YYYY"'; 

, 나는 그것이 문제를 해결했다고 가정하지만, 나는이 단계에서 100 % 확실하지 않다.

DBMS_XMLSave.setBatchSize()를 대체하지 않았습니다. 이것이 성능에 영향을 미칠지 모르겠다.

내가 직접 코드를 수정 공용 동의어를 사용하는 대신, 그것은 현재 다음과 같습니다

procedure insert_xml(p_xmlDoc in clob, p_tableName in varchar2) is 
     v_insCtx DBMS_XMLStore.ctxType; 
     v_rows number; 
    begin 
     v_insCtx := DBMS_XMLStore.newContext(p_tableName); -- get the context handle 
     EXECUTE IMMEDIATE 'ALTER SESSION SET NLS_DATE_FORMAT = "MM/DD/YYYY"'; 
     v_rows := DBMS_XMLStore.insertXML(v_insCtx, p_xmlDoc); -- this inserts the document 
     DBMS_XMLStore.closeContext(v_insCtx); -- this closes the handle 
    exception 
     when OTHERS then 
      raise_application_error(-20001,'An error was encountered. - '||SQLCODE||' -ERROR- '||SQLERRM); 
    end insert_xml; 
    procedure update_xml(p_xmlDoc in clob, p_tableName in varchar2, p_key in varchar2) is 
     v_updCtx DBMS_XMLStore.ctxType; 
     v_rows number; 
    begin 
     v_updCtx := DBMS_XMLStore.newContext(p_tableName); -- get the context 
     EXECUTE IMMEDIATE 'ALTER SESSION SET NLS_DATE_FORMAT = "MM/DD/YYYY"'; 
     DBMS_XMLStore.clearUpdateColumnList(v_updCtx); -- clear the update settings.. 
     DBMS_XMLStore.setKeyColumn(v_updCtx, p_key); -- set EMPNO as key column 
     v_rows := DBMS_XMLStore.updateXML(v_updCtx, p_xmlDoc); -- update the table. 
     DBMS_XMLStore.closeContext(v_updCtx); -- close the context..! 
    exception 
     when OTHERS then 
      raise_application_error(-20001,'An error was encountered. - '||SQLCODE||' -ERROR- '||SQLERRM); 
     end update_xml; 
관련 문제