Using dbms_xmlsave
I am trying to save contents of xml file into database tables. I know I have to use dbms_xmlsave.insertxml, but it does not allow you to work with multiple tables, so I created a view to join 2 tables together. But when I try to insert into the view I get this error:
ERROR at line 1:
ORA-29532: Java call terminated by uncaught Java exception:
oracle.xml.sql.OracleXMLSQLException: Exception
'oracle.jdbc.driver.OracleSQLException:ORA-01732: data manipulation operation
not legal on this view
' encountered during processing ROW element 1All prior XML row changes were
rolled back. in the XML document.
ORA-06512: at "SYS.DBMS_XMLSAVE", line 91
ORA-06512: at line 31
My xmldatagram looks like this:
<?xml version = "1.0"?>
<warranty_claim>
<ROW>
<customer_claim_no>12345</customer_claim_no>
<claim_date>2003-SEP-24</claim_date>
<repair_shop_site_name>test supplier</repair_shop_site_name>
<failed_part_no>12345</failed_part_no>
<other_part>
<other_part_item>
<customer_claim_no>12345</customer_claim_no>
<part_no>54321</part_no>
<unit_price>10.2</unit_price>
<quantity>10</quantity>
<total_price>102</total_price>
</other_part_item>
<other_part_item>
<customer_claim_no>12345</customer_claim_no>
<part_no>98767</part_no>
<unit_price>20.2</unit_price>
<quantity>10</quantity>
<total_price>202</total_price>
</other_part_item>
</other_part>
</ROW>
</warranty_claim>
create or replace type ph_other_part as object(
customer_claim_no varchar2(100),
part_id number,
part_no varchar2(100),
description varchar2(100),
unit_price number,
quantity number,
total_price number,
part_failed varchar2(100))
create or replace type ph_othpart_tab as table of ph_other_part
create or replace view ph_wc_view
as select customer_claim_no,
claim_date,
repair_shop_site_name,
failed_part_no,
CAST(MULTISET(select customer_claim_no,
part_id,
part_no,
description,
unit_price,
quantity,
total_price,
part_failed
from ph_wc_part pwp
where pwp.customer_claim_no = pwc.customer_claim_no
) AS sys.ph_othpart_tab ) other_part
from ph_warranty_claim pwc
main script
declare
insCtx dbms_xmlsave.ctxType;
rowcount number:=0;
v_tablename varchar2(100):='ph_wc_view';
xmldoc clob;
errorNum number;
errorMsg varchar2(200);
begin
begin
select data
into xmldoc
from cic.cic_temp
where data_id = 2;
exception when others then
dbms_output.put_line('Error getting xmldoc. '||sqlerrm(sqlcode));
end;
insCtx := dbms_xmlsave.newcontext(v_tablename);
dbms_xmlsave.setIgnoreCase(insCtx,1);
dbms_xmlsave.clearupdatecolumnlist(insCtx);
dbms_xmlsave.setupdatecolumn(insCtx,'customer_claim_no');
dbms_xmlsave.setupdatecolumn(insCtx,'claim_date');
dbms_xmlsave.setupdatecolumn(insCtx,'repair_shop_site_name');
dbms_xmlsave.setupdatecolumn(insCtx,'failed_part_no');
dbms_xmlsave.setupdatecolumn(insCtx,'other_part');
rowcount := dbms_xmlsave.insertXML(insCtx,xmldoc);
dbms_xmlsave.closecontext(insCtx);
commit;
dbms_output.put_line('Rows inserted: '||rowcount);
end;
Hi,
For your XML file I think you just need to enclose XML elemnts in ROWSET AND ROW TAGS - so xml should look like :
<ROWSET>
<ROW>
<DEPT>
</DEPT>
and just pass it as CLOB to dbms_xmlsave.insertXML proc.
I hope it should work.
I am also trying to insert XML file but with a bit complex structure having multiple nested elements.
I am not sure how to transform the external XML file to wrap it in ROWSET/ROW using XSLT. It's mandatory to use ROWSET/ROW tags to be able to insert in oracle tables. I am facing this problem right now. I am using object views to accomplish the purpose but still needs to figure out the way to apply stylesheet to incoming XML file.
If you come to know of any way, pls do let me know also.
Thanks
Similar Messages
-
Update the passed XML in a PL/SQL procedure and then use DBMS_XMLSAVE
hi folks,
This is a great forum and most of you guys were awesome in replying to complex queries........
I have a small issue, I am trying to do a bulk insert from my application by constructing an XML result set and pass that XML to the SP as a CLOB and using DBMS_XMLSAVE package to insert it to the oracle table. It works like a charm for me when this is as straight forward as this. But when my requirement is, I need to generate sequence numbers for a particular column (Primary key column), while for other columns I pass values from the UI (as a XML object which my SP accepts as a CLOB), i am at a loss for solution to achieve this. It would mean, that I have to generate the sequence numbers for each row and then update this value to the passed XML clob. Any indicators on how to achieve this?
I found this solution at one of the thread which might most probably help me,
declare
2 l_cnt number;
3 begin
4 select count(*) into l_cnt from books,xmltable('/Books/Book' passing object_value);
5 for i in 1..l_cnt loop
6 update books set object_value =
7 updatexml(object_value,'/Books/Book['||i||']/BookID', xmlelement("BookID",sequence_bookid.nextval))
8 where existsnode(object_value,'/Books/Book['||i||']')=1;
9 end loop;
10 end;
11 /
But here, they are trying to update a XMLTable book, but in my case the XML is a clob object and not a XML table. Will this solution work for my case as well? Please provide any pointers to me... Thanks...First if your version of Oracle has DBMS_XMLSTORE, use that instead.
Reason: {thread:id=876376} (See Marco's response).
It is possible you could run into issues, but you should start with DBMS_XMLSTORE.
Since you will have the XML in the SP, treat the data as an XMLType instead of a CLOB for as long as you can since you need to do UpdateXML on it.
For your sample PL/SQL code, lines 4-5 are replaced with the WHILE loop shown in Method 2 at
{message:id=3610259}.
The UPDATE would be replaced with the following pseudocode
SELECT UPDATEXML(<l_xmltype_variable>, ...)
INTO <l_xmltype_variable>
FROM dual;
Once your loop is done, l_xmltype_variable would contain your updated XML and then you can use that XMLType directly on the call to DBMS_XMLSTORE or convert it back to a clob via
l_clob_variable := l_xmltype_variable.getClobVal(); -
Error while using dbms_xmlsave.UpdateXML and dbms_xmlsave.insertXML
The Record I am trying to insert/update has the following structure
<ROWSET>
<ROW>
<COL1>123</COL1>
</ROW>
</ROWSET>
Table structure is as below
COL1 INT [Primary constraint]
COL2 VARCHAR2(100) NOT NULL [but has default value of 'COL2_Default']
Now since the XML doesn't have the entry for COL2, I am explicitly setting the columns to be updated/inserted using dbms_xmlsave.setUpdateColumn.
I use the logic the following logic to insert/update the table
-- set the primary key column name. This forms the where clause for update statement
dbms_xmlsave.setkeycolumn(l_Context , 'COL1');
-- cXML have the XML structure mentioned above
l_rows := dbms_xmlsave.updateXML(l_Context, cXML);
IF l_rows <= 0 THEN -- which means no rows found for update
l_rows := dbms_xmlsave.insertXML(l_Context, cXML);
END IF;
Now when the excution of dbms_xmlsave.updateXML happens Java Runtime Error is thrown.
ORA-29532: Java call terminated by uncaught Java exception: oracle.xml.sql.OracleXMLSQLException: 'java.sql.SQLException: Missing IN or OUT parameter at index:: 5' encountered during processing ROW element 0. All prior XML row changes were rolled back. in the XML document.
The version of oracle I am using is 9.2.0.6.0.
Please let me know if anyone has any idea on this error.Found maybe an applicable reference...
On http://publib.boulder.ibm.com/infocenter/wasinfo/v4r0/index.jsp?topic=/com.ibm.support.was.doc/html/Java_2_Connectivity_(J2C)/1163246.html
it says:
* Application code is missing a setXXX method call somewhere.
* There might be a problem in the Oracle JDBC driver code.
If the latter is the problem than you should or try a different JDBC driver or (which is probably the best solution anyway) create an iTar with Oracle support via metalink.oracle.com
Other references can also be found on the internet when using google which could be applicable. Search on keywords: "Missing IN or OUT parameter at index"
Message was edited by:
mgralike -
Error while using DBMS_XMLSave package...
Hi All,
I am using DBMS_XMLSave package and when I try to execute the following code, it is giving me error "Java call terminated by uncaught Java exception:"
I am executing following code ....
declare
insCtx DBMS_XMLSave.ctxType;
begin
insCtx := DBMS_XMLSave.newContext('scott.emp');
end;
I am getting following error ...
ERROR at line 1:
ORA-29532: Java call terminated by uncaught Java exception:
java.lang.ExceptionInInitializerError
ORA-06512: at "SYS.DBMS_XMLSAVE"
ORA-06512: at line
Please help me to overcome the problem....
Thanx in advance ,
YogeshFound maybe an applicable reference...
On http://publib.boulder.ibm.com/infocenter/wasinfo/v4r0/index.jsp?topic=/com.ibm.support.was.doc/html/Java_2_Connectivity_(J2C)/1163246.html
it says:
* Application code is missing a setXXX method call somewhere.
* There might be a problem in the Oracle JDBC driver code.
If the latter is the problem than you should or try a different JDBC driver or (which is probably the best solution anyway) create an iTar with Oracle support via metalink.oracle.com
Other references can also be found on the internet when using google which could be applicable. Search on keywords: "Missing IN or OUT parameter at index"
Message was edited by:
mgralike -
Using dbms_xmlsave.insertXML
Hi all,
I am reading an XML data which has similar structure to:
<dept>
<name> department name </name>
<loc> department location </loc>
<emp>
<fisrt> first name for first employee </first>
<last> last name for first employee </last>
</emp>
<emp>
<first> first name for second employee </first>
<last> last name for second employee </last>
</emp>
</dept>
I do not have control on the structure of the XML data as I am reading it from external source. Now I have created a table as follows:
SQL> create type emprec as object (
first varchar2(30),
last varchar2(30)
SQL> create type empreclist as table of emprec;
SQL> create table mydept (
name varchar2(30),
loc varchar2(50),
emp empreclist);
Now when I use the dbms_xmlsave.insertXML , the columns name,loc are populated but the column emp is not populated and i I define the emp column as (emprec) type, then only the last <emp></emp> data is inserted.
Any ideas how to read all the <emp></emp> data into the dept table ?Hi,
I have been trying for a while to get a nested collection loaded. The oracle documentation is no help. But what i did in the end is this. I built the object table, inserted the nested collection manual and then ran the command line XSU (documented in the app. dev. guide xml) to save the tabledata as XML (only one record) with the -withDTD switch. This creates a XML with inline DTD. Surprise surprise when you load that document it does work, even when you add more nested rows in the document. This XML file will also show you if you build the table correctly. It seems that XSU needs the DTD to be able to load nested collections.
If you are running windows the command line utility can be run like this
java -cp c:\oracle\ora81\rdbms\jlib\xsu12.jar;c:\oracle\ora81\lib\xmlparserv2.jar;c:\oracle\ora81\jdbc\lib\classes12.zip OracleXML getXML -user "username/password" -withDTD "select * from yourtable" >g:\xmlfiles\output.xml
have fun -
Error opening external DTD 'Segnatura.dtd' using dbms_xmlsave.insertXML
I've been trying to insert a document in a table. All works fine
if the xml doesn't contains the doctype element!
If I add the row
<!DOCTYPE Segnatura SYSTEM "Segnatura.dtd">
to my xml I get the error:
oracle.xml.sql.OracleXMLSQLException: Error opening external DTD
'Segnatura.dtd'.
If I specify all the path "file:///temp/Segnatura.dtd" the insert
works, but I don't want to do in that way beacause I don't want
to modify the original xml that i'm inserting!
In the package dbms_xmlsave I have no ways to change the
basedir/baseurl
or to setValidationMode to false like in xmlparser package.
Is there any way to solve this problem??
Thank's in advance
Mauro
This is an example scratch of my xml doc:
<?xml version = '1.0' encoding = 'ISO-8859-1'?>
<!DOCTYPE Segnatura SYSTEM "Segnatura.dtd">
<Segnatura versione="2001-05-07"
xmlns:xml="http://www.w3.org/XML/1998/namespace" xml:lang="it">
</Segnatura>Hy Steven, thank's for your attention.
I'm not using the xsql servlet.
I'm reading an xml file coming from the file system and I want to
import it in the db using a java stored proc.
I also have the dtd file (Segnatura.dtd) but I don't know where
to put in on the server.
If I run my java program and I put Segnatura.dtd in the execution
classpath on the program the xml is loaded fine.
If I load the stored proc in the db then I don't know where to
put the dtd. Do I have to put the directory containing the dtd in
the server classpath and the restart the db maibe?
thank's
mauro -
Loading data into XMLType column using dbms_xmlsave.insertxml get ORA-29532
The following simple test case succeeded in 9.2.0.1 but failed in 9.2.0.2.
CREATE OR REPLACE procedure InsertXML(xmlDoc IN VARCHAR2, tableName IN VARCHAR2) is
insCtx DBMS_XMLSave.ctxType;
rows number;
begin
insCtx := DBMS_XMLSave.newContext(tableName); -- get the context handle
rows := DBMS_XMLSave.insertXML(insCtx,xmlDoc); -- this inserts the document
dbms_output.put_line(to_char(rows) || ' rows inserted');
DBMS_XMLSave.closeContext(insCtx); -- this closes the handle
end;
CREATE TABLE XMLtable
(column1 xmltype)
exec insertxml('<?xml version = "1.0"?><ROWSET><ROW><COLUMN1><TEST>HELLO</TEST></COLUMN1></ROW></ROWSET>', 'XMLTABLE');Hi,
For your XML file I think you just need to enclose XML elemnts in ROWSET AND ROW TAGS - so xml should look like :
<ROWSET>
<ROW>
<DEPT>
</DEPT>
and just pass it as CLOB to dbms_xmlsave.insertXML proc.
I hope it should work.
I am also trying to insert XML file but with a bit complex structure having multiple nested elements.
I am not sure how to transform the external XML file to wrap it in ROWSET/ROW using XSLT. It's mandatory to use ROWSET/ROW tags to be able to insert in oracle tables. I am facing this problem right now. I am using object views to accomplish the purpose but still needs to figure out the way to apply stylesheet to incoming XML file.
If you come to know of any way, pls do let me know also.
Thanks -
Default insertion for missing elements using DBMS_XMLSave.insertXML
Hi,
I am trying to insert default values for some columns, without having those column names as elements in the xml document. Is it possible to do so?? This is the code I am using for now, but it inserts null values for missing elements in the xml document.
insCtx := DBMS_XMLSave.newContext ('TABLENAME'); -- get the context
rows := DBMS_XMLSave.insertXML (insCtx, p_xmlDoc); -- insert the doc
DBMS_XMLSave.closeContext (insCtx); -- close the handleOnly thing I noticed with dbms_xmlstore.insertXML, was when my xml document had "<?xml version = "1.0" ?>" at the start, it gave an error "LPX-00209: PI names starting with XML are reserved"That's probably due to the XML document not starting exactly with "<", like this :
SQL> DECLARE
2
3 xmldoc clob := '
4 <?xml version="1.0"?>
5 <ROWSET>
6 <ROW>
7 <COL1>1</COL1>
8 <COL2>TEST1</COL2>
9 </ROW>
10 <ROW>
11 <COL1>2</COL1>
12 </ROW>
13 </ROWSET>';
14
15 ctx dbms_xmlstore.ctxHandle;
16 numrows number;
17
18 BEGIN
19
20 ctx := dbms_xmlstore.newContext('MY_TABLE');
21 numrows := dbms_xmlstore.insertXML(ctx, xmldoc);
22 dbms_xmlstore.closeContext(ctx);
23
24 END;
25 /
DECLARE
ERROR at line 1:
ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00209: PI names starting with XML are reserved
ORA-06512: at "SYS.DBMS_XMLSTORE", line 78
ORA-06512: at line 21 However, it runs OK if the prolog actually starts the character stream :
SQL> DECLARE
2
3 xmldoc clob := '<?xml version="1.0"?>
4 <ROWSET>
5 <ROW>
6 <COL1>1</COL1>
7 <COL2>TEST1</COL2>
8 </ROW>
9 <ROW>
10 <COL1>2</COL1>
11 </ROW>
12 </ROWSET>';
13
14 ctx dbms_xmlstore.ctxHandle;
15 numrows number;
16
17 BEGIN
18
19 ctx := dbms_xmlstore.newContext('MY_TABLE');
20 numrows := dbms_xmlstore.insertXML(ctx, xmldoc);
21 dbms_xmlstore.closeContext(ctx);
22
23 END;
24 /
PL/SQL procedure successfully completed.
With the dbms_xmlsave.inserXML, [...] it wont insert the default column values.Now that's strange...
I understand there could be differences in the parsing implementation, but in the end both processes must issue an INSERT into the target table using plain SQL, so I really wonder why default values are not applied.
I'll try to reproduce when I have access to a Java-enabled db. -
Can't replicate data inserted using DBMS_XMLSAVE.insertXML
Enviroment:
OS: SLES 10 SP2
Database Version: 11.1.0.6
I have configured an Oracle Streams environment compose by two database. The first is the source where a local capture process should captures dml changes from some tables. If I insert some data using a classic dml insert operation the changes are replicated without problems. The problem is when the tables are populated using the DBMS_XMLSAVE.insertXML procedure. With that implementation there isn't data replication. I think DBMS_XMLSAVE.insertXML must generate redolog so the capture process should capture the changes from them but it doesn't seems to be like that.
I need some suggestion about this matter, thank you.Here you are
CREATE TABLE TEST.HABI
ID_DATA NUMBER,
ID_HOCU INTEGER,
ID_HABI INTEGER,
DESCRIPTION VARCHAR2(1000 BYTE)
TABLESPACE USERS
PCTUSED 0
PCTFREE 10
INITRANS 1
MAXTRANS 255
STORAGE (
INITIAL 32M
NEXT 80K
MINEXTENTS 1
MAXEXTENTS UNLIMITED
PCTINCREASE 0
BUFFER_POOL DEFAULT
LOGGING
NOCOMPRESS
NOCACHE
NOPARALLEL
MONITORING;
I'am not performe explicit commit here you are the procedure:
FUNCTION import(p_id_data IN INTEGER,
p_lote IN INTEGER,
p_fecha_hotel DATE,
p_error IN OUT NOCOPY CLOB,
p_hab_habi IN OUT NOCOPY CLOB,
p_hcl_clie IN OUT NOCOPY CLOB,
p_hcl_habi IN OUT NOCOPY CLOB,
p_hcl_hist IN OUT NOCOPY CLOB,
p_tel_llpr IN OUT NOCOPY CLOB) Return integer
AS
ctx DBMS_XMLSAVE.ctxType;
v_rows NUMBER;
v_err_msg VARCHAR(4000);
v_cant integer;
BEGIN
IF length(p_error) > (length('<?xml version = ''1.0''?><ENL_TRAN_ERROR/>') + 3) THEN
ctx := DBMS_XMLSAVE.newContext('ENL_TRAN_ERROR');
DBMS_XMLSAVE.setRowTag(ctx, 'ROW');
--BEGIN
v_rows := DBMS_XMLSAVE.insertXML(ctx, p_error);
--EXCEPTION WHEN OTHERS THEN
-- NULL;
--END;
DBMS_XMLSAVE.closeContext(ctx);
END IF;
IF length(p_hab_habi) > (length('<?xml version = ''1.0''?><ENL_TRAN_HAB_HABI/>') + 3) THEN
ctx := DBMS_XMLSAVE.newContext('ENL_TRAN_HAB_HABI');
DBMS_XMLSAVE.setRowTag(ctx, 'ROW');
--BEGIN
v_rows := DBMS_XMLSAVE.insertXML(ctx, p_hab_habi);
--EXCEPTION WHEN OTHERS THEN
-- NULL;
--END;
DBMS_XMLSAVE.closeContext(ctx);
END IF;
IF (INSTR(p_hcl_clie, '&')<>0) THEN
p_hcl_clie := replace(p_hcl_clie, '&', '&');
END IF;
IF length(p_hcl_clie) > (length('<?xml version = ''1.0''?><ENL_TRAN_HCL_CLIE/>') + 3) THEN
ctx := DBMS_XMLSAVE.newContext('ENL_TRAN_HCL_CLIE');
DBMS_XMLSAVE.setRowTag(ctx, 'ROW');
--BEGIN
v_rows := DBMS_XMLSAVE.insertXML(ctx, p_hcl_clie);
--EXCEPTION WHEN OTHERS THEN
-- NULL;
--END;
DBMS_XMLSAVE.closeContext(ctx);
END IF;
IF length(p_hcl_habi) > (length('<?xml version = ''1.0''?><ENL_TRAN_HCL_HABI/>') + 3) THEN
ctx := DBMS_XMLSAVE.newContext('ENL_TRAN_HCL_HABI');
DBMS_XMLSAVE.setRowTag(ctx, 'ROW');
--BEGIN
v_rows := DBMS_XMLSAVE.insertXML(ctx, p_hcl_habi);
--EXCEPTION WHEN OTHERS THEN
-- NULL;
--END;
DBMS_XMLSAVE.closeContext(ctx);
END IF;
IF length(p_hcl_hist) > (length('<?xml version = ''1.0''?><ENL_TRAN_HCL_HABI_HIST/>') + 3) THEN
ctx := DBMS_XMLSAVE.newContext('ENL_TRAN_HCL_HABI_HIST');
DBMS_XMLSAVE.setRowTag(ctx, 'ROW');
--BEGIN
v_rows := DBMS_XMLSAVE.insertXML(ctx, p_hcl_hist);
--EXCEPTION WHEN OTHERS THEN
-- NULL;
--END;
DBMS_XMLSAVE.closeContext(ctx);
END IF;
IF length(p_tel_llpr) > (length('<?xml version = ''1.0''?><ENL_TRAN_TEL_LLPR/>') + 3) THEN
ctx := DBMS_XMLSAVE.newContext('ENL_TRAN_TEL_LLPR');
DBMS_XMLSAVE.setRowTag(ctx, 'ROW');
--BEGIN
v_rows := DBMS_XMLSAVE.insertXML(ctx, p_tel_llpr);
--EXCEPTION WHEN OTHERS THEN
-- NULL;
--END;
DBMS_XMLSAVE.closeContext(ctx);
END IF;
END import;
I hope you can help me. -
Error when using DBMS_XMLSave package
Hi,
I am a novice at XML technology. And although I have picked up on the basics, please do bear with my questions. My requirement is that we are receiving XML files in a particular format (as below), which I need to load into Oracle tables.
<?xml version="1.0"?>
<Root_Element>
<Examinee>
<MACode>A</MACode>
<TestingJID>TN</TestingJID>
<ExamineeID>100001</ExamineeID>
<CreateDate>20020221</CreateDate>
<Demographic>
<InfoDate>20020221</InfoDate>
<FirstTime>1</FirstTime>
<LastName>JANE</LastName>
<FirstName>DOE</FirstName>
<MiddleInitial>C</MiddleInitial>
<LithoNumber>73</LithoNumber>
<IdType>1</IdType>
<IdNumber>30738</IdNumber>
<DOB>19630525</DOB>
<EthnicCode>1</EthnicCode>
<GenderCode>2</GenderCode>
<MilitaryCode/>
<MSCode/>
<RFT01>1</RFT01>
<RFT02></RFT02>
<RFT03></RFT03>
<RFT17></RFT17>
<StreetAddress>SomeAddress</StreetAddress>
<City>SomeCity</City>
<StateCode>TN</StateCode>
<ZipCode>37000</ZipCode>
<EdLevel>8</EdLevel>
<SU01> </SU01>
<SU02> </SU02>
<SU03> </SU03>
<SU04> </SU04>
<TestCenterCode>34</TestCenterCode>
<PassStatus>1</PassStatus>
<CompleteStatus>1</CompleteStatus>
<CompleteDate>20020221</CompleteDate>
<TotStdScore>268</TotStdScore>
<AvgStdScore>53.6</AvgStdScore>
<CredJID>TN</CredJID>
<CredStatus>1</CredStatus>
<CredNbr>100001</CredNbr>
<CredDate>20020310</CredDate>
</Demographic>
<Test>
<TestDate>20020221</TestDate>
<TestNbr>1</TestNbr>
<SrlNbr>13773784</SrlNbr>
<Fmt>3</Fmt>
<Frm>23</Frm>
<Raw>47</Raw>
<Top>10</Top>
<RN1>30</RN1>
<RN2>35</RN2>
<RN3></RN3>
<RS1>4</RS1>
<RS2>4</RS2>
<RS3></RS3>
<ESY>8</ESY>
<Std>58</Std>
<Rnk>81</Rnk>
<FErr>0</FErr>
<EErr>0</EErr>
<MErr>0</MErr>
<JErr>0</JErr>
<AErr>0</AErr>
<QErr>0</QErr>
<Best>1</Best>
<Inactive>0</Inactive>
<Response>4,4,4,2,2,5,1,1,2,4,5,5,5,1,3,1,5,4,1,1,5,3,1,3,5,4,4,4,4,3,1,4,1,1,3,4,2,4,4,3,1,1,4,5,4,3,1,2,4,1, , , , , </Response>
</Test>
<Test>
<TestDate>20020221</TestDate>
<TestNbr>2</TestNbr>
<SrlNbr>13773784</SrlNbr>
<Fmt>3</Fmt>
<Frm>23</Frm>
<Raw>46</Raw>
<Std>53</Std>
<Rnk>67</Rnk>
<FErr>0</FErr>
<EErr>0</EErr>
<MErr>0</MErr>
<JErr>0</JErr>
<AErr>0</AErr>
<QErr>0</QErr>
<Best>1</Best>
<Inactive>0</Inactive>
<Response>5,3,5,3,2,4,3,4,3,3,2,4,3,2,2,3,2,2,2,3,1,4,3,5,4,3,1,1,2,1,2,4,5,5,2,5,4,5,4,1,3,2,1,4,1,3,2,4,2,1,1,1,4,4,5,2,3,2,1, , , , , </Response>
</Test>
</Examinee>
</Root_Element>
We will be creating new tables, so taking into account the nested structures we decided to go the object-relational route. The "Examinee" is on the higher level with a single "Demographic" and multiple "Test" under it. This is what we have created.
create or replace type DEMOGRAPHIC_TY as object (
InfoDate VARCHAR2(50),
FirstTime VARCHAR2(50),
LastName VARCHAR2(50),
FirstName VARCHAR2(50),
MiddleInitial VARCHAR2(50),
LithoNumber VARCHAR2(50),
IdType VARCHAR2(50),
IdNumber VARCHAR2(50),
DOB VARCHAR2(50),
EthnicCode VARCHAR2(50),
GenderCode VARCHAR2(50),
MilitaryCode VARCHAR2(50),
MSCode VARCHAR2(50),
RFT01 VARCHAR2(50),
RFT02 VARCHAR2(50),
RFT03 VARCHAR2(50),
RFT17 VARCHAR2(50),
StreetAddress VARCHAR2(50),
City VARCHAR2(50),
StateCode VARCHAR2(50),
ZipCode VARCHAR2(50),
EdLevel VARCHAR2(50),
SU01 VARCHAR2(50),
SU02 VARCHAR2(50),
SU03 VARCHAR2(50),
SU04 VARCHAR2(50),
TestCenterCode VARCHAR2(50),
PassStatus VARCHAR2(50),
CompleteStatus VARCHAR2(50),
CompleteDate VARCHAR2(50),
TotStdScore VARCHAR2(50),
AvgStdScore VARCHAR2(50),
CredJID VARCHAR2(50),
CredStatus VARCHAR2(50),
CredDate VARCHAR2(50),
CredNbr VARCHAR2(50));
create or replace type TEST_TY as object (
TestDate VARCHAR2(50),
TestNbr VARCHAR2(50),
SrlNbr VARCHAR2(50),
Fmt VARCHAR2(50),
Frm VARCHAR2(50),
"Raw" VARCHAR2(50),
Top VARCHAR2(50),
RN1 VARCHAR2(50),
RN2 VARCHAR2(50),
RN3 VARCHAR2(50),
RS1 VARCHAR2(50),
RS2 VARCHAR2(50),
RS3 VARCHAR2(50),
ESY VARCHAR2(50),
Std VARCHAR2(50),
Rnk VARCHAR2(50),
FErr VARCHAR2(50),
EErr VARCHAR2(50),
MErr VARCHAR2(50),
JErr VARCHAR2(50),
AErr VARCHAR2(50),
QErr VARCHAR2(50),
Best VARCHAR2(50),
Inactive VARCHAR2(50),
Response VARCHAR2(100));
create or replace type TEST_NT as table of TEST_TY;
create table EXAMINEE (
MACode VARCHAR2(50),
TestingJID VARCHAR2(50),
ExamineeID VARCHAR2(50),
CreateDate VARCHAR2(50),
Demographic DEMOGRAPHIC_TY,
Test TEST_NT)
nested table Test store as Test
CREATE DIRECTORY XML_DIR AS 'C:\TestXML';
CREATE TABLE XML_TEMP (key NUMBER, f_lob BFILE);
INSERT INTO XML_TEMP VALUES (1,BFILENAME('XML_DIR','M01.XML'));
And this is the procedure,
CREATE OR REPLACE PROCEDURE loadxml AS
insCtx sys.DBMS_XMLSave.ctxType;
rows number;
fil BFILE;
buffer RAW(32767);
len INTEGER;
insrow INTEGER;
BEGIN
SELECT f_lob INTO fil FROM xml_temp WHERE key = 1;
DBMS_LOB.FILEOPEN(fil,DBMS_LOB.FILE_READONLY);
len := DBMS_LOB.GETLENGTH(fil);
DBMS_LOB.READ(fil,len,1,buffer);
insCtx := sys.DBMS_XMLSave.newContext('examinee'); -- get the context handle
rows := sys.DBMS_XMLSave.insertXML(insCtx,buffer); -- this inserts the document
sys.DBMS_XMLSave.closeContext(insCtx); -- this closes the handle
IF DBMS_LOB.FILEISOPEN(fil) = 1 THEN
DBMS_LOB.FILECLOSE(fil);
END IF;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('In Exception');
DBMS_OUTPUT.PUT_LINE(SQLERRM(SQLCODE));
IF DBMS_LOB.FILEISOPEN(fil) = 1 THEN
DBMS_LOB.FILECLOSE(fil);
END IF;
end;
And when I execute this, it gives an error,
In Exception
ORA-29532: Java call terminated by uncaught Java exception: oracle.xml.sql.OracleXMLSQLException: Start of root element expected.
I have tried to follow the XML Developer Guide as much possible, but might be missing something.
H E L P !!!!
Thanks.When I try the describe, it says object not found. If I go into OEM, I don't see that package either. Again, I didn't create that database, but I thought the XML DB stuff was installed by default with the database. Is there a way to add that package after the database is created?
Thanks,
Andrew -
Storing XML using XSU, object VIEW and INSTEAD OF trigger
Here is the point:
I've got 2 tables which are linked:
CREATE TABLE dept (
deptno NUMBER PRIMARY KEY,
deptname VARCHAR2(20)
CREATE TABLE emp (
empno NUMBER PRIMARY KEY,
empname VARCHAR2(20),
deptno NUMBER REFERENCES dept(deptno)
I've got the following message, which I want to insert in the tables using XSU (I already have a PL/SQL stored procedure which work perfectly for insertion into 1 table, using DBMS_XMLSave.insertXML or xmlgen.insertXML):
<DEPT>
<DEPTNO>10</DEPTNO>
<DEPTNAME>IT</DEPTNAME>
<EMP>
<EMPNO>1</EMPNO>
<EMPNAME>John</EMPNAME>
</EMP>
<EMP>
<EMPNO>1</EMPNO>
<EMPNAME>Phil</EMPNAME>
</EMP>
</DEPT>
So I've created the following object:
CREATE TYPE emp_t AS OBJECT
empno NUMBER,
empname VARCHAR2(20)
CREATE TYPE emplist_t AS TABLE OF emp_t;
CREATE TYPE dept_t AS OBJECT
deptno NUMBER,
deptname VARCHAR2(20),
emplist emplist_t
Now I understand that I should create an object VIEW and an INSTEAD OF trigger (That's what I read many times),
but I don't know how to structure the view and the trigger.
Could you help? (Example of a similar context, piece of code)
Thanks a lot
MarionHi John,
I have exactly the same issue as you experienced back in January. I have a complex data modelling requirement which requires the need to pivot rows into columns using ROW_NUMBER() and PARTITION clauses. To hide the complexity from the middle tier, I have created a database view and appropriate INSTEAD OF triggers and mapped my EO to the view. I have overriden the lock() method on the EO implementation class (to avoid ORA-02014) and would like to try the same solution you used with the pl/sql call to lock the record.
My question is, how did you manage the release of the lock if the transaction was not rolled back or committed by your application i.e. if the user closed the browser for instance.
In my naivity, I would like to think that the BC4J framework would release any locks for the database session when it found the servlet session to be terminated however my concern is that the lock would persist and cause complications.
Any assistance greatly appreciated (if you would be willing to supply your lock() method and pl/sql procedure logic I would be even more grateful!).
Many thanks,
Dave
London -
DBMS_XMLSave.insertXML slow.
Hi,
I am using the function DBMS_XMLSave.insertXML to take a clob (XML file) off a queue, and process
the file into a table. I am finding that inserting 10,000 records (from a single clob) is taking over 30secs.
This is an order of magnitude out from where I expected to be. It would be nice (clean) to
be able to order my App this way using XML documents and Advanced Queues, but if I cant get the times
down further I will need to look at other alternatives.
Is there a way to improve the performance of DBMS_XMLSave.insertXML?
Thanks,
MattLucky boy, you have DBMS_XMLSave in sys schema, I have not....
Did you try to use dbms_xmlsave.setBatchSize ? Set about 10% of total xml size (in bytes). This should improve performace greatelly. -
DBMS_XMLSave.insertXML
Hi All,
I am using DBMS_XMLSave.insertXML to read a XMl file and store it in a table.
But the maximum record I am able to insert into the oracle table is limited around 80...
I have tried using DBMS_XMLSave.setBatchSize but it is not helping me.
let me know if there is any way to increase the buffer?Lucky boy, you have DBMS_XMLSave in sys schema, I have not....
Did you try to use dbms_xmlsave.setBatchSize ? Set about 10% of total xml size (in bytes). This should improve performace greatelly. -
DBMS_XMLSave.insertXML ORA-01024 error
DBMS_XMLSave.insertXML ORA-01024 error
The following error is being produced when trying to use DBMS_XMLSave.insertXML. The xml datagram was produced from the view using DBMS_XMLQuery.getXML. This works fine for non object nested views.
Does anyone know of a problem with this approach or syntax.
Thanks
ORA-29532: Java call terminated by uncaught Java exception:
oracle.xml.sql.OracleXMLSQLException: 'oracle.jdbc.driver.OracleSQLException:
ORA-01024: invalid datatype in OCI call
' encountered during processing ROW element 1. All prior XML row changes were
rolled back. in the XML document.
ORA-06512: at "SYSTEM.DBMS_XMLSAVE", line 91
ORA-06512: at "SJS.IMRES", line 60
ORA-06512: at "SJS.IMRES", line 99
ORA-06512: at line 6
*************** Insert Procedure *******************
PROCEDURE InsertXml(xmlDoc IN clob, tableName IN VARCHAR2) IS
insCtx DBMS_XMLSave.ctxType;
rows number;
BEGIN
DBMS_OUTPUT.PUT_LINE('INsertXml - '||tableName);
insCtx := DBMS_XMLSave.newContext(tableName);
rows := DBMS_XMLSave.insertXML(insCtx,xmlDoc);
dbms_output.put_line('InsertXML -'||rows);
DBMS_XMLSave.closeContext(insCtx);
COMMIT;
END InsertXml;
*************** Object view *******************
CREATE OR REPLACE TYPE sjs.imres_error_type AS OBJECT
("ResponseErrorCode" VARCHAR2(10),
"ResponseErrorDesc" VARCHAR2(4000))
CREATE OR REPLACE TYPE sjs.imres_errors_type AS TABLE OF imres_error_type
CREATE OR REPLACE VIEW sjs.imresponse
AS SELECT ith.a_id AS "ArrestNumber",
CAST(MULTISET(SELECT ire.errorcode,
ire.errordesc
FROM sjs.imresponseerrors ire
WHERE ire.ith_id = ith.ith_id) AS imres_errors_type) AS "Errors"
FROM sjs.imtransactionhistory ith
*************** XML DATAGRAM *******************
<?xml version = '1.0'?>
<ROWSET>
<ROW>
<ArrestNumber>2</ArrestNumber>
<Errors>
<Errors_ITEM>
<ResponseErrorCode>CODE 2</ResponseErrorCode>
<ResponseErrorDesc>DESC 2</ResponseErrorDesc>
</Errors_ITEM>
<Errors_ITEM>
<ResponseErrorCode>CODE 1</ResponseErrorCode>
<ResponseErrorDesc>DESC 1</ResponseErrorDesc>
</Errors_ITEM>
</Errors>
</ROW>
</ROWSET>It seems to be related to an insert/update for the same context
having different columns with "values" in it.
I have 3 rows. For the AMT column the first row has 151.56,
the second row has 100.00, the third row has .00
The third row fails with this error :
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error
ORA-06512: at "MTRSTEST.KIM_RTL_XML_PKG", line 150
ORA-29532: Java call terminated by uncaught Java exception:
oracle.xml.sql.OracleXMLSQLException:
Invalid context handle specified.
ORA-06512: at "SYS.DBMS_XMLQUERY", line 170
ORA-06512: at "MTRSTEST.KIM_RTL_XML_PKG", line 193
ORA-29532: Java call terminated by uncaught Java exception:
oracle.xml.sql.OracleXMLSQLException:
Expected 'EOF'.
ORA-06512: at "MTRSTEST.KIM_TEST", line 197
ORA-06512: at line 1
If I change the third row to say 10.00, for example, it works
fine.
We had not been on xdk9 yet, I'm having them install xdk9 and
we'll see if the problem persists. -
DBMS_XMLSAVE.updatexml basic problem - bug?
I want to update a column that is also the key. i.e. \
update salary_tab set salary=15000 where salary=10000
how can I accomplish this using DBMS_XMLSAVE.UPDATEXML?
Trying to figure out for 6 hours no solution :( help!
Thanks in advance!Hi Pavan,
Thanks for looking into it. However, this does not work - all the examples I found on the net dealt with different key and update columns. My case is when the key and update columns lists are overlapping.
Thus,
Key Column List = SALARY
Update Column List = SALARY
the problem is that I dont know how to specify the rowset xml now.
<ROWSET>
<ROW>
<SALARY>10000</SALARY>
<ROW>
</ROWSET>
how can I specify 2 nodes for salary - one to find which row to update and one to specify the new upated value.
Is this a missing functionality in DBMS_XMLSAVE??
Maybe you are looking for
-
Godaddy IMAP email no longer downloads with iOS 8.1
no problem sending, however, no new email will download. I rebooted, deleted account, added it (which it adds fine), it just no longer downloads email.
-
IOS7.1.2 Update on 5S...Phone not coming out of recovery mode
After the recent update ios7.1.2 5S doesn't come out of the Recovery mode....Even on hard resetting the iphone i still see the "itunes and connector symbol" on the iphone. Not sure how to get rid of this. Could you please help me get back my phone t
-
Hyphenation not working for Russian language
Hello All, We really shocked to see that hyphenation not working for Russian language, anyone faced this issue? Please let us know how to rectify this issue since we need to complete one of the project with Russian language. Thanks in advance. Pravee
-
I want to connect my new MacBook Pro via DisplayPort to a Dell U2410m monitor. But the signal only comes as YPbPr, no RGB and bad quality. Is there any solution? It works with the mini display port to DVI adapter from Apple but I want to use the Disp
-
I left my install disc in a hotel room in San Francisco. I can not find the drivers for the Wireless Mighty Mouse anywhere on Apple's site. Do I have to buy another mouse just to get the drivers? Why doesn't Apple have the option to download them? Am