I have inherited an application that uses an Oracle database on the backend. The database was originally using a full version of Oracle but we have moved it across to Oracle XE. Oracle XE does not appear to support Oracle XML SQL Utility (which includes DBMS_XMLSave), or at least I have been unable to figure out how to install it.
According to this link (http://ellebaek.wordpress.com/2011/01/27/converting-between-oracle-data-and-xml/):
Like DBMS_XMLQUERY, DBMS_XMLSAVE is implemented in Java and hence it's not supported with Oracle Database Express Edition.
The stored procedures in the database use DBMS_XMLSave, but from this link (https://forums.oracle.com/forums/thread.jspa?threadID=530048) it appears that DBMS_XMLSave has been replaced by DBMS_XMLStore:
The DBMS_XMLSTORE PL/SQL package was introduced in Oracle Database 10g Release 1. This package performs DML operations on relational or object tables inside the database, based on the contents of an XML document.
Note that before Oracle Database 10g, this functionality existed in another PL/SQL package, called DBMS_XMLSAVE.
I tried the solution in the link:
CREATE OR REPLACE PUBLIC SYNONYM DBMS_XMLSAVE FOR DBMS_XMLSTORE;
GRANT EXECUTE ON DBMS_XMLSAVE TO PUBLIC;
This did fix a large portion of the errors, however I was left with a few problem lines:
DBMS_XMLSave.setDateFormat(v_insCtx, 'MM/dd/yyyy');
DBMS_XMLSave.setBatchSize(v_updCtx, -1);
DBMS_XMLSave.setDateFormat(v_updCtx, 'MM/dd/yyyy');
DBMS_XMLStore does not appear to support these methods. Digging around I think I've found a way to work around the setDateFormat. According to this link (http://ellebaek.wordpress.com/2011/01/27/converting-between-oracle-data-and-xml/) DBMS_XMLStore uses NLS settings for date/time values. This link (http://www.tiplib.com/231/nls-parameter-session-logon-trigger) pointed out that NLS settings could be changed in a stored procedure like this:
BEGIN
DBMS_SESSION.SET_NLS('NLS_DATE_FORMAT','YYYYMMDD');
COMMIT;
END;
So I am hoping that I can replace the setDateFormat lines like this:
-DBMS_XMLSave.setDateFormat(v_insCtx, 'MM/dd/yyyy'); -- remove
+DBMS_SESSION.SET_NLS('NLS_DATE_FORMAT','MM/dd/yyyy'); -- insert
I was unable to find a replacement for setBatchSize.
So my questions are:
Am I approaching this in the right way, or is there a better approach?
Will the DBMS_XMLSave.setDateFormat(v_insCtx, 'MM/dd/yyyy') -> DBMS_SESSION.SET_NLS('NLS_DATE_FORMAT','MM/dd/yyyy') change work?
Is there a replacement for setBatchSize? Is it necessary to replace setBatchSize?
Generally if someone asked a question like question 2 above I would tell them to try it and tell me, but I currently can't get the code to compile and I don't have a known working baseline. I could remove the problem lines and it would probably produce some results, but I would not be clear if the results were correct or not. Removing the problem lines and trying to check the results will be my approach from here.
The original code is as follows:
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;
Thanks for your assistance.