Loading XML file to a table via DBMS_XMLSave.insertXML
Simon Rushton, February 28, 2002 - 6:01 am UTC
Tom, Sean,
Thanks sooo much for putting the time in to look at my problem. I appreciate it.
I have a reply - I'll mail it to thomas.kyte@oracle.com.
Cheers,
Simon
Inserting NON-UTF8 into UTF8 *requires* Java?
Basil, October 31, 2002 - 9:56 am UTC
If I read Sean Dillon's answer correctly, if I have a 9i database using UTF8 as the character set, I'm *forced* to use Java to load XML documents from the filesystem into the database?
I've got the following function (gratuitously ripped off
from the XML DB developer guide, but with some kind
of naming convention imposed on it):
CREATE OR REPLACE FUNCTION getDocument( p_filename IN VARCHAR2,
p_dirname IN VARCHAR2 DEFAULT 'XMLDIR' )
RETURN CLOB
IS
v_bfile bfile;
v_clob clob;
BEGIN
v_bfile := BFILENAME( p_dirname, p_filename );
DBMS_LOB.OPEN( v_bfile );
DBMS_LOB.CREATETEMPORARY( v_clob, TRUE, DBMS_LOB.SESSION );
DBMS_LOB.LOADFROMFILE( v_clob, v_bfile, DBMS_LOB.GETLENGTH( v_bfile ) );
DBMS_LOB.CLOSE( v_bfile );
RETURN v_clob;
END getDocument;
/
1* select dbms_lob.substr(getDocument( 'Test.xsl'),1,200) from dual;
DBMS_LOB.SUBSTR(GETDOCUMENT('TEST.XSL'),1,80)
--------------------------------------------------------------------------------
¿
My database is set up for UTF-8. The file, of course, is
in the default character set for my machine, which
runs Windows 2000.
Can this work, or must I really endure the headache of
connecting, preparing, binding, and all that other junk
I use PL/SQL to avoid? If the latter, I think Oracle needs to reconsider their recent moves to push PL/SQL to the status of second-class language.
Which is the right way to convert XML data into ROWS?
Mihail Daskalov, April 16, 2003 - 1:55 pm UTC
We have some concerns loading data from XML into oracle table.
The XML structure is not like the one expected from insertXML procedure.
instead of
<ROWSET>
<ROW num="1">
<SURNAME>Rushton</SURNAME>
<FORENAMES>Simon</FORENAMES>
<DOB>30/01/1975</DOB>
<CHARGE>Eating too much cake</CHARGE>
</ROW>
</ROWSET>
we have structure similar to
<DATA>
<timeseries>
<series_key>
<dimension>USD</dimension>
<dimension>S312</dimension>
<dimension>CODE_635</dimension>
</series_key>
<observation>
<single_period>
<period_value>200304</period_value>
</single_period>
<value>87345.34</value>
<status>A</status>
</observation>
</timeseries>
<!-- many other time series -->
</ROWSET>
The structure comes from not-yet-standard GESMES (General Statistical Message) as XML.
Which would be the right way to load the information in the database.
case 1, transform it somehow with XSL, and use insertXML
case 2, use extract with XPATH to get the values from the database.
I wrote a query
SELECT
extract(value(d),'//series_key/dimension[1]/text()').getStringVal() as dim1,
extract(value(d),'//series_key/dimension[2]/text()').getStringVal() as dim2,
extract(value(d),'//series_key/dimension[3]/text()').getStringVal() as dim3,
extract(value(d),'//value/text()').getStringVal() as val
FROM xml_test t,
TABLE(XMLSequence(XMLType(t.contents).extract('//data/timeseries'))) d;
table xml_test contains 1 rows, and the contents column is CLOB.
It seems to do what I expect, but it is quite slow.
Processing a 2MB file takes more than 3 minutes on a P4 to produce 7000 rows.
Is there way to speed it up?
What if I load it with XML Schema which is registered in XML DB? Will it help? How to do it?
About case 1:
someone mentioned XSLT is not good for large XML files, because the whole document must be in memory.
</code>
http://marvel.oracle.com/pls/otn/f?p=17000:8:::::F17000_P8_DISPLAYID:1520615643 <code>
Thank you Tom ,
for providing the best answers for the Oracle Developer Community
Loading XML
Fred Howell, June 27, 2003 - 11:29 am UTC
I am just starting to work with XML and Oracle. I wasn't aware of DBMS_XMLSAVE but it clearly resolved my problem of loading XML data into Oracle. I am not working on a tool to use AQ and XML to pass messages between databases. The XML adds a level of flexibility to the message as i don't have to be concerned about the structure of the payload as i would be an object_type. XML in a CLOB really make my life easier. Thanks for the tip!
Problems loading XML document using DBMS_LOB.LOADCLOBFROMFILE
saj, July 02, 2003 - 9:16 am UTC
i am using oracle 9i r2 and have used the dbms_lob/dbms_xmlgen packages to create XML files. These XML files are then sent to translators and we have to load them back into the database.
My problem is that using DBMS_LOB.LOADCLOBFROMFILE is not returning the entire XML document to me. It is truncating the document
Here are the procedures
PROCEDURE p_Read_Text_From_File
( p_directory IN VARCHAR2
,p_filename IN VARCHAR2
,p_clob OUT CLOB
,p_debug IN BOOLEAN DEFAULT FALSE
,p_Errnum OUT NUMBER )
IS
vClob CLOB;
vInFile BFILE;
vErrNum NUMBER;
vdest INTEGER := 1;
VSRC INTEGER := 1;
vWarn INTEGER;
vLang INTEGER := 0;
vMaxSize NUMBER := DBMS_LOB.LOBMAXSIZE;
BEGIN
p_Errnum := 1;
IF p_directory is NULL or LENGTH(p_directory) = 0 THEN
p_ErrNum := -20004;
RAISE_APPLICATION_ERROR(p_ErrNum, 'Please provide the name of the directory from where to read the File.');
END IF;
IF p_filename is NULL or LENGTH(p_filename) = 0 THEN
p_ErrNum := -20004;
RAISE_APPLICATION_ERROR(p_ErrNum, 'Please provide the name of the file to be read.');
END IF;
IF p_Debug THEN
DBMS_OUTPUT.PUT_LINE('directory = ' ||p_directory || '; filename = ' || p_fileName);
DBMS_OUTPUT.PUT_LINE('vMaxSize = ' ||vMaxSize);
END IF;
vClob := Empty_Clob();
vClob := ' ';
vInFile := bfilename( p_Directory, p_filename);
dbms_lob.fileopen( vInfile, dbms_lob.file_readonly);
if p_Debug then
dbms_output.put_line('filesize=' || dbms_lob.getlength(vInFile));
end if;
DBMS_LOB.LOADCLOBFROMFILE (vClob,vInfile, dbms_lob.LOBMAXSIZE,vdest,vsrc, 0,vLang,vWarn);
dbms_lob.fileclose( vInFile );
IF p_debug THEN
dbms_output.PUT_LINE('clobsize=' || dbms_lob.GETLENGTH(vClob));
END IF;
p_Clob := vClob;
EXCEPTION
WHEN OTHERS THEN
p_ErrNum := PKG_UTILITIES.WW_ERROR('PKG_XML_UTILS', 'p_Read_Text_From_File ', SQLCODE, SQLERRM);
END p_Read_Text_From_File ;
PROCEDURE p_READ_XML(pTableName IN VARCHAR2 default null)
IS
vTableName VARCHAR2(50) := pTableName;
vDataClob CLOB;
vFileName VARCHAR2(50);
vFileExt VARCHAR2(4) := '.xml';
vDir VARCHAR2(25) default 'GMF_XML';
vSQL VARCHAR2(32767);
v_Errnum NUMBER;
LCLOB CLOB;
vID number;
--vDate varchar2(8) default to_char(sysdate, 'YYYYMMDD');
BEGIN
IF vTableName IS NULL THEN
vTableName := 'COURSE';
END IF;
vFileName := vTableName || vFileExt;
PKG_XML_UTILS.p_Read_Text_From_File
( vDir,vfilename,vDataClob,TRUE,v_Errnum);
dbms_output.put_line('Size of dataclob=' || dbms_lob.GETLENGTH(vDataClob));
IF v_ErrNum = 1 THEN
SELECT tmp_clob_seq.nextval INTO vID FROM DUAL;
insert into tmp_clob values (vID, vDataClob);-- returning THECLOB into lclob;
IF SQL%ROWCOUNT > 0 THEN
COMMIT;
END IF;
SELECT THECLOB INTO LCLOB FROM TMP_CLOB WHERE ID = vID;
DBMS_OUTPUT.PUT_LINE('THECLOB=' || DBMS_LOB.GETLENGTH(LCLOB));
END IF;
END p_Read_XML;
The actual File system size of the ARTICLE.XML is 5907 KB
5097*1094
Here is the output of the sizes from DBMS_OUTPUT
directory = GMF_XML; filename = ARTICLE.xml
vMaxSize = 4294967295 (LOBMAXSIZE)
filesize=6047883
clobsize=6047876
Size of dataclob=6047876
THECLOB=6047876
Can you tell me why is my clob not getting the complete file? ( it is less than lobmaxsize)
July 02, 2003 - 9:27 am UTC
try this:
dbms_lob.loadfromfile( l_blob, l_bfile,
dbms_lob.getlength( l_bfile ) );
much easier -- rather than me debugging your code, give that a try first.
The original code that I submitted works fine
saj, July 02, 2003 - 12:03 pm UTC
The original code that I submitted works fine
and it worked because, I opened the XML document in Notepad and used save as to save in UTF_8 encoding. (I can't do this for every single file because there will be hundreds in the directory).
The file was then read properly, no truncation occured
This XML document was created using the
following procedure? How can I get my XML generated in UTF_8 encoded format?
v_CTX := DBMS_XMLGEN.newContext(p_sqltext);
DBMS_XMLGEN.setConvertSpecialChars (v_CTX, FALSE);
dbms_lob.createtemporary(v_clob,true,dbms_lob.session);
v_CLOB := DBMS_XMLGEN.getXml(v_CTX);
dbms_xmlgen.CLOSECONTEXT(v_ctx);
and to write the xml to file I use
v_Amt NUMBER DEFAULT 255;
v_Offset NUMBER DEFAULT 1;
v_File := utl_file.fopen(v_directory, p_fileName, p_mode, 32767);
while ( v_Offset < v_Length )
loop
utl_file.put(v_File, dbms_lob.substr(v_Clob,v_Amt,v_Offset) );
utl_file.fflush(v_File);
v_Offset := v_Offset + v_Amt;
end loop;
utl_file.new_line(v_File);
utl_file.fclose(v_File);
How can I get UTL_FILE to write the file in UTF_8 format?
July 02, 2003 - 12:22 pm UTC
utl_file uses the databases character set.
thanks for the prompt response
saj, July 02, 2003 - 2:57 pm UTC
I ran the following SQL and found that my database is UTF8
select * from nls_database_parameters where parameter like '%CHARACTERSET';
NLS_CHARACTERSET= UTF8
NLS_NCHAR_CHARACTERSET= UTF8
and
NLS_LANGUAGE = AMERICAN
I found a similar problem in this page/forum. Is it related to my problem (there was no response to this thread)
Inserting NON-UTF8 into UTF8 *requires* Java? October 31, 2002
Reviewer: Basil
Also what I noticed is that if the XML or the data from SQL that generates the XML have special characters, the file is written as a UTF-8 encoded file. If it doesn't, it is plain ASCII file.
And my issue is that even if it is a UTF-8 file I still have to open the file in Notepad/do a save as UTF-8. Then read the XML and use DBMS_XMLSave to insert into the db.
The exception I get is :
Unhandled Error in p_Load_XML_To_Table - ORA-29532: Java call terminated by uncaught Java exception: oracle.xml.sql.OracleXMLSQLException: Invalid char in text.
If I manually save the file as UTF_8, then I dont get the exception mentioned above.
July 02, 2003 - 3:13 pm UTC
I'll have to refer you to support -- I haven't really worked through this situation myself.
Thanks a million
SAJ, July 02, 2003 - 3:42 pm UTC
Appreciate all the time spent.
I am hoping our DBA's will be able get this resolved from Oracle support or metalink (as they call it!)
Put BLOB into XML ?
Sasa, September 01, 2003 - 9:05 am UTC
Hi Tom
I found in doc that only way to load blob in XML is as follows(in FAQ):
"Answer: XML requires all characters to be interpreted, therefore there is no provision for including raw binary data in an XML document. That being said, you can UUENCODE the data and include it in a CDATA section. The limitation on the encoding technique is to be sure it only produces legal characters for a CDATA section."
Could you please provide some example for that?
Current release Oracle 9.2.0.4
Regards
September 01, 2003 - 9:29 am UTC
there are many uuencode (or base64 encode -- even better) in java. tons of them. you just need to look a bit.
RICHARD, November 03, 2003 - 11:56 pm UTC
Hi Tom,
Related to the top question, does XDK 9.2.0.6 (most recent) resolve the issue of non-utf-8 xml file upload into utf-8 database as we discussed many times before?
Please advice what is the solution. I hope by installing XDK 9.2.06, uploading non-utf-8 xml file is not an issue anymore, please confirm.
Thanks for help.
Richard
Loading XML into multiple table also condidering sequence numbers
mwor, March 11, 2004 - 5:04 pm UTC
Hi Tom,
Thanks very much for your help as always.
I have a xml and would like to import data into multiple tables.
Following is the sample xml
<A>
<Name>Tom</Name>
<order>Order1</order>
<C>
<part>part1</part>
<part>part2</part>
</C>
<order>Order2</order>
<C>
<part>part3</part>
</C>
</A>
<A>
<Name>John</Name>
<order>Order3</order>
<C>
<part>part4</part>
</C>
</A>
The following is the output after importing data into 3 tables
Table A ( pk = A_ID )
A_ID( seq num ) | Name
________________|_____
A1 |Tom
A2 |John
TABLE B ( pk = B_ID )
B_ID( seq num ) | A_ID | oRDER_NAME
________________________________|___________
B1 | A1 | order1
B2 | A1 | order2
B3 | A2 | order3
TABLE C ( pk = B_ID and Part_ID)
B_ID | Part_ID | Part Name
_____________________________________________
B1 | p1 | Part1
B1 | p2 | part2
B2 | p3 | part3
B3 | p4 | part4
Problem Defination:
Currently I parse the xml in VB and insert 1 record in Table A, then using select take the sequence num generated ( A1 ), parse xml then insert another record in Table B using A1, then using select get sequence number of Table B , parse xml and insert 1 record in Table C using sequnce number of Table B.. then next record in Table A and so on..
Instead of VB program parsing xml and calling Oracle for each Insert then select seq num again insert in another table , Can something be done on oracle end ?
Can I acheive something called bulk insert or some PL SQL routine or something in oracle where I just pass the XML and configure which tables to insert ( properly reading the sequence of oe table and inserting into column of another table ).
My xml can be huge with lots of records around 500,000.
Using VB and looping through each record in xml then insert/select each record is extremely time consuming.
Thanks in advance
Wor
March 12, 2004 - 9:23 am UTC
</code>
https://docs.oracle.com#index-XML <code>
shows you what is available in the DB, yes, you can send the XML straight to plsql and parse it in the database and do whatever you want with it.
sorry I forgot to mention I have Oracle 8.1.7
mwor, March 11, 2004 - 6:34 pm UTC
March 12, 2004 - 9:32 am UTC
then most of what you want is in 9i
inserting through XML file
omer, May 07, 2004 - 2:59 am UTC
Hi!
I am very new in using XML.
I am trying to insert data in emp table using Xml file but error come
here is code
CREATE TABLE EMP
(EMPNO NUMBER(4) NOT NULL,
ENAME VARCHAR2(10),
JOB VARCHAR2(9),
MGR NUMBER(4),
HIREDATE DATE,
SAL NUMBER(7,2),
COMM NUMBER(7,2),
DEPTNO NUMBER(2));
data in xml file is
<?xml version="1.0" ?>
<ROWSET>
<ROW num="1">
<EMPNO>9999</EMPNO>
<ENAME>KING</ENAME>
<JOB>PRESIDENT</JOB>
<HIREDATE>11/17/1981 0:0:0</HIREDATE>
<SAL>5000</SAL>
<DEPTNO>10</DEPTNO>
</ROW>
</ROWSET>
I have a procedure with this code
create or replace procedure insProc(xmlDoc IN CLOB, tableName IN VARCHAR2) is
insCtx DBMS_XMLSave.ctxType;
rows number;
begin
insCtx := DBMS_XMLSave.newContext(tableName);
rows := DBMS_XMLSave.insertXML(insCtx,xmlDoc);
DBMS_XMLSave.closeContext(insCtx);
end;
pl/sql block to insert data is
declare
l_document varchar2(100) := 'C:\insert.xml';
begin
insproc(l_document,'OMER.EMP');
end;
but error come
ERROR at line 1:
ORA-29532: Java call terminated by uncaught Java exception: oracle.xml.sql.OracleXMLSQLException: Start of root element expected.
ORA-06512: at "SYS.DBMS_XMLSAVE", line 65
ORA-06512: at "OMER.INSPROC", line 6
ORA-06512: at line 4
i have dowload all this data and code from otn.
my database version is
9.2.0.1.0
May 07, 2004 - 8:12 am UTC
hmm, looks suspiciously just like the original Q&A on this page doesn't it.
Convert XML document into varchar
Rama Kalagara, May 12, 2004 - 6:26 pm UTC
I am trying to traverse through an XML document using DOM and replacing some of the text node values. Finally i want to convert the updated dom document into varchar.How do i do that? I do really appreciate if you could help me in this regard.
Thanks
Rama
May 13, 2004 - 9:45 am UTC
what is the dom document "in" in the first place?
if clob, clobs are just like varchar2's but you can in plsql
x := dbms_lob.substr( clob, 32765, 1 )
upto 32k or in sql, use dbms_lob.substr upto 4000 bytes.
what is the dom document "in" in the first place?
Rama Kalagara, May 13, 2004 - 2:17 pm UTC
Tom,
Thanks for the prompt response. I miss typed dom document,
the correct xml document.
Here is the senario
1. An xml string will passed to my program.
2. I am comverting the xml string to a document
3. Pasrse the document and update the text nodes
4. Now i have to the convert the xml document back to string(varchar2) and return to the caller procedure.
How do i convert an xml document into varchar?
Thanks
Rama
May 13, 2004 - 3:22 pm UTC
i don't know what you mean by coverting a string into a document now :)
hows about a code snippet or something?
dbms_lob.substr returns nothing after 256K
Olga, May 27, 2004 - 6:31 pm UTC
Hi Tom,
I have a problem with a clob and dbms_lob.substr. Please look at the example. First I select the CLOB-Val of a xmltype. dbms_lob.getlength shows me 329483 characters. Ok, but when I do a dbms_lob.substr after character 262145 (256K), the function returns nothing.
If I write the same CLOB into a table and do a dbms_lob.substr, I get characters behind the 256K border.
declare
l_clob CLOB;
begin
SELECT ( d.xml_source.TRANSFORM( XMLTYPE( get_document( 'ub.xsl' )))).getclobval()
INTO l_clob
FROM fop.fop_document d
WHERE fop_id = 99
;
dbms_output.put_line( 'LENGTH: '||dbms_lob.getlength( l_clob ));
dbms_output.put_line( 'SUBSTR 262140-262145: ['||dbms_lob.SUBSTR( l_clob, 5, 262140 )||']');
dbms_output.put_line( 'SUBSTR 262140-262150: ['||dbms_lob.SUBSTR( l_clob, 10, 262140 )||']');
dbms_output.put_line( 'SUBSTR 262145-262150: ['||dbms_lob.SUBSTR( l_clob, 5, 262145 )||']');
dbms_output.put_line( '---------------------------------------------');
DELETE test_jk;
INSERT INTO test_jk VALUES( l_clob );
SELECT t
INTO l_clob
FROM test_jk
;
dbms_output.put_line( 'LENGTH: '||dbms_lob.getlength( l_clob ));
dbms_output.put_line( 'SUBSTR 262140-262145: ['||dbms_lob.SUBSTR( l_clob, 5, 262140 )||']');
dbms_output.put_line( 'SUBSTR 262140-262150: ['||dbms_lob.SUBSTR( l_clob, 10, 262140 )||']');
dbms_output.put_line( 'SUBSTR 262145-262150: ['||dbms_lob.SUBSTR( l_clob, 5, 262145 )||']');
end;
/
LENGTH: 329483
SUBSTR 262140-262145: [ <fo:]
SUBSTR 262140-262150: [ <fo:]
SUBSTR 262145-262150: []
---------------------------------------------
LENGTH: 329483
SUBSTR 262140-262145: [ <fo:]
SUBSTR 262140-262150: [ <fo:block]
SUBSTR 262145-262150: [block]
Could it be a bug or should I invest more time in reading the docs ;-)
Bye,
Olga
PS: I use Oracle 10.1.0.2 on Windows
May 27, 2004 - 9:01 pm UTC
looks "buggy", yes.
Performance slow with dbms_xmlsave
Nilanjan Ray, August 11, 2004 - 1:41 am UTC
Hi Tom,
I have been trying to load a XML file (50 MB) using dbms_xmlsave. Previously it was giving an error:
ORA-29532: Java call terminated by uncaught Java exception:
java.lang.OutOfMemoryError. But I have fixed it by making a call to the following function
--- From Metalink
CREATE OR REPLACE FUNCTION
setMaxMemorySize(num NUMBER) RETURN NUMBER
IS LANGUAGE java name
'oracle.aurora.vm.OracleRuntime.setMaxMemorySize(long)
returns LONG';
/
My question is:
1. Where does this additional memory is allocated from when I call the above function? I see no change in large pool, shared pool or java pool sizes.
2. After fixing the problem the performance seems to be horrible, just to load the file into a temporary table using dbms_xmlsave.insertxml (takes more than an hour). What necessary steps are needed to improve the performance. I understand it uses a lot of temporay tablespace, but then I haven't exactly found an area to lay my hand to tame the slow performance.
Here's a list of some relevant parameters:
SQL> show parameter shared_p
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
shared_pool_reserved_size big integer 6710886
shared_pool_size big integer 134217728
SQL> show parameter JAVA_MAX_SESSIONSPACE_SIZE
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
java_max_sessionspace_size integer 0
SQL> show parameter JAVA_SOFT_SESSIONSPACE_LIMIT
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
java_soft_sessionspace_limit integer 0
SQL> show parameter JAVA_POOL_SIZE
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
java_pool_size big integer 58720256
SQL> show parameter large_p
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
large_pool_size big integer 58720256
SQL> select getMaxMemorySize from dual;
GETMAXMEMORYSIZE
----------------
268435456
This has been set t0 "468435456" to get the proess running without java.lang.OutOfMemoryError".
SQL> show sga
Total System Global Area 806428792 bytes
Fixed Size 454776 bytes
Variable Size 276824064 bytes
Database Buffers 528482304 bytes
Redo Buffers 667648 bytes
Thnsks in advance for your replay
Regards
Ray
August 11, 2004 - 9:57 am UTC
1) pga memory -- in the process.
2) i'll "asksean" to peek at this if he has time.
Load XML data
Nilanjan Ray, October 19, 2004 - 3:36 am UTC
Hi Tom,
Hope you had a nice time out :). Missed all your reviews during your vacation.
It's regarding the performance problem using dbms_xmlsave in my earlier post. Surprisingly I had posted this at several forums (OTN and Metalink) but have not received any satisfactory answer.
Thought to do a bit research on this. This is what I discovered. Oracle uses the DOM parser to load XML data. The drawback is that it builds the entire tree in memory before processing the data. This is the cause of poor performance for large XML files. Please correct me if I am wrong.
I need to use SAX parser (java approach), then probably a java stored procedure. Again your opinion regarding this would be most valuable.
Since I am not a java guy I was looking for a piece of code for implementation (huh! asking too much :-D.) Waiting for your precious response.
Thanks in advance
Ray
October 19, 2004 - 9:05 am UTC
SAX is better for larger files yes, less resource intensive -- more of a stream approach rather than build a big structure.
from xml interface to flatfile-external table
Nilanjan Ray, February 15, 2005 - 7:20 am UTC
Tom,
I am trying to shift one of our interface from xml data loading using dbms_xmlsave to flatfile(external table). However the constraint is that the xml has one of its tag directly mapped to a clob column in a database table, and external table does not support any of the large data types.
Please suggest an approach.
Regards
February 15, 2005 - 3:29 pm UTC
how big is the data in the tagged xml ?
from xml interface to flatfile-external table
Nilanjan, February 16, 2005 - 12:16 am UTC
Thanks tom for the prompt response.
The xml file can itself be around 60 MB. The details of one such row data is pasted below(sorry it's a bit long).
The clob(inline) column I was refering to is tagged as "<PROG_SYNOP>".
- <ROW>
<CONTRACT_NO>5728</CONTRACT_NO>
<EPISODE_NO>1</EPISODE_NO>
- <PROG_SYNOP>
- <![CDATA[
CHANCE HAS BEEN GARDENER TO THE OLD MAN FOR AS LONG AS HE CAN REMEMBER. WHEN HIS EMPLOYER DIES HE IS ORDERED TO LEAVE THE HOUSE. CHANCE IS A SIMPLE FELLOW, QUITE UNPREPARED FOR THE TOUGH WORLD OUTSIDE THE GARDEN WALLS. WANDERING THROUGH THE STREETS HE IS KNOCKED DOWN BY A LIMOSINE. THE ANXIOUS OWNER OF THE VEHICLE, EVE RAND TAKES HIM TO THE HOSPITAL WING OF HER PALATIAL HOME. THERE CHANCE MEETS HER DYING HUSBAND, BEN. BEN LIKES CHANCE & ITNRODUCES HIM TO THE PRESIDENT, WHO USES CHANCE'S HOMESPUN PLANT PHILOSOPHY IN HIS SPEECH ON THE ECONOMY. CHANCE BE- COMES A CELEBRITY OVERNIGHT; APPEARING ON TV CHAT SHOWS, ATTENDING EMBASSY FUNCT IONS. EVE FINDS CHANCE STRANGE & ATTRACTIVE ALMOST WITH BEN'S CONSENT SHE THROWS HERSELF AT HIM, BUT HE HAS TO WATCH TV TO FIND OUT WHAT A MAN DOES WITH A WOMAN. BEN DIES LEAVING PART OF HIS HUGE FINANCIAL EMPIRE TO CHANCE. & HIS RICH & POWER FUL COLLEAGUES DECIDE TO MAKE CHANCE THEIR NEXT PRESIDENTIAL CANDIDATE.
~~~~~~~~~~
BEING THERE
All his life, Chance has lived with the Old Man and his cook, Louise. Though he can neither read nor write, and has never set foot outside the house, his world is, (in it's own way), quite complete: he happily cares for the garden and spends his leisure hours watching television.
When the Old Man dies, the house is closed and he is sent away by the estate's executors. As he walks down the streets of Washington DC, he sees the real world as with a child's eyes.
His enchantment is abruptly shattered, however, when he is hit by a limousine. It's occupant, Eve Rand, insists he come to her home for medical attention and en route, mistaking his announced profession for his name, thinks he is Chauncey Gardiner.
Eve Rand lives on a palatial estate with her husband, Benjamin, an enormously wealthy financier with equally enormous political influence. Benjamin's health is rapidly deteriorating and there is a physician in residence. Dr Robert Allenby, who immediately attends to Chance's injury.
So delighted is everyone by Chance's cooperative spirit - he disdains the very idea of a lawsuit - that he is invited to dinner where his naive wit and apparent candour are especially appreciated by Benjamin.
A few days later, the President of the United States comes to call on his dying friend. Chance is included in a discussion on the country's economic crisis, and so impresses them by his invocation of gardening metaphors that he is quoted in a major Presidential address shortly thereafter.
Overnight, Chauncy Gardiner - formerly Chance, the gardener - becomes a celebrity. Television hosts compete for his appearance on their shows; publishers offer him book contracts; the President as well as the Soviet Union's Ambassador order full-scale investigations on his background.
Most importantly, Benjamin Rand puts wheels in motion for Chance to participate in his empire when he has departed this earth - and also gives his blessing to an enhanced relationship between Chance and his wife, Eve.
Chance gracefully floats through this bewildering chain of events. He especially relishes seeing his own image on the television screen: "being there" validates his existence; now he is really a part of the world.
Though frantic efforts are made by every conceivable investigatory unit to unearth information on his past, Chauncey Gardiner remains a mystery blank on the pages of history. All conclude, therefore, that he is even more important than they thought; they believe unknown agents have astutely destroyed all potentially incriminating evidence. Chance's stature grows.
Eve Rand's attempts to deepen her relationship with Chance are frustrating because he does not respond to her advances. His reticence causes her to respect him even more, however, and she alters her behaviour according to his expressed wishes, as she understand them. "I Like to Watch" becomes his byword, and thus she, in a monumental misunderstanding attempts to please him though a kind of sexual "performance".
Benjamin Rand's funeral is a major event with the President and other important personages in attendance. As the pall-bearers, a group of powerful industrialists, discuss a candidate for the next presidential election, Eve breaks away from the procession.
She finds Chance walking through the woods, caring for seedlings. He says he has been waiting for her; he remembers Benjamin's final plea to look after her as a delicate flower, and we know he will do so.
As the President intones famous aphorisms of the departed into a microphone, the pall-bearers definitively settle on their candidate; it will be Chauncey Gardiner.
CAST
Chance Peter Sellers
Eve Rand Shirley MacLane
Benjamin Rand Melvyn Douglas
President "Bobby" Jack Warden
Dr Robert Allenby Richard Dysart
Vladimir Skrapinov Richard Basehart
Louise Ruth Attaway
Thomas Franklin Dave Clennon
Sally Hayes Fran Brill
Johanna Franklin Denise DuBarry
Lolo (Boy on Corner) Oteil Burbridge
Abbaz (Kid with Knife) Ravenell Keller, III
Policeman (by White House) Brian Corrigan
Old Woman (Asked for lunch) Alfredine Brown
David (Chauffeur) Donald Jacob
Jeffery (Liveryman) Ernest M McClure
Perkins (Butler) Kenneth Patterson
Wilson (Chance's Valet) Richard Venture
Arthur (Rand's Valet) Arthur Grundy
Lewis (Doorman) W C "Mutt" Burton
Billings (X-Ray Technician) Henry D Hawkins
Mrs Aubrey (Rand's Secretary) Georgine Hall
Constance (Nurse) Nell P Leaman
Teresa (Nurse) Villa Mae P Barkley
First Lady Alice Hirson
Kaufman (Presidential Advisor) James Noble
Presidential Aides Timothy Shaner
William F Williams
William Dance
Jim Aar
William Lubin
Secret Service Agents
Woltz Gerald C McNabb, Jr
Riff Hoyt Clark Harris, Jr
CREDITS
Directed by Hal Ashby
Produced by Andrew Braunsberg
Screenplay by Jerzy Kosinski
Based on the Novel by Jerzy Kosinski
Director of Photography Caleb Deschanel
Production Designer Michael Haller
Costumes Designed by May Routh
Executive Producer Jack Schwartzman
Associate Producer Charles Mulvehill
Music John Mandel
Casting Lynn Stalmaster
Production Sound Mixer Jeff Wexler
Editor Don Zimmerman
Production Manager Charles B Mulvehill
1st Assistant Director David S Hamburger
2nd Assistant Director Toby Lovallo
Production Office Coordinator Teresa Stokovic
Accountant Kenneth Ryan
Extra Casting David Welch
Production Assistants Charles Clapsaddle
Michael Flowers
Gregory Palmer
05728/JM
BEING THERE
]]>
</PROG_SYNOP>
- <CMSNG_EDITOR>
- <![CDATA[ June Dromgoole
]]>
</CMSNG_EDITOR>
- <EPISODE_TITLE>
- <![CDATA[ BEING THERE
]]>
</EPISODE_TITLE>
- <PROG_ITC_CATG_CD>
- <![CDATA[ FILM
]]>
</PROG_ITC_CATG_CD>
- <PROG_C4_CATG_CD>
- <![CDATA[ FF
]]>
</PROG_C4_CATG_CD>
- <PROG_BOARD_CATG_CD>
- <![CDATA[ 11300
]]>
</PROG_BOARD_CATG_CD>
<REPEAT_STATUS />
<IMPORT_PIRATE_FLG>N</IMPORT_PIRATE_FLG>
</ROW>
Regards
February 16, 2005 - 7:56 am UTC
all i asked was "how big", I didn't need a book!
bigger than varchar2(4000), therefore, you right now will not be using an external table.
any other approach
Nilanjan Ray, February 16, 2005 - 8:18 am UTC
sorry Tom for bothering you with the unnecessary lengthy post. In this case is xml the only way forward.
Regards
February 16, 2005 - 8:42 am UTC
sqlldr would be another.
custom code would be another.
there are many other ways -- but the external table doesn't do lobs.
used table of xmltype
Nilanjan Ray, February 18, 2005 - 4:36 am UTC
Thanks Tom,
I will be exploring sqlldr. but as of now I loaded the xml table of xmltype.
CREATE TABLE XMLTABLE OF XMLType;
when I try to insert the clob data it into a table containg clob datatype I get "end-of-file on communication channel"
create table t1(a clob);
SQL>insert into t1
2 SELECT extractValue(value(t),'/PROG_SYNOP') PROG_SYNOP
3 FROM XMLTABLE X,
4 TABLE (
5 xmlsequence ( extract(value(X),'/ROWSET/ROW/PROG_SYNOP') )
6 ) t;
insert into toto
*
ERROR at line 1:
ORA-03113: end-of-file on communication channel
My lob data is much larger than varch2(4000).
I even tried doing this:
create or replace procedure ins_clob as
l_clob clob;
begin
SELECT dbms_lob.getlength(extractValue(value(t),'/PROG_SYNOP')) PROG_SYNOP
into l_clob
FROM XMLTABLE X,
TABLE (
xmlsequence ( extract(value(X),'/ROWSET/ROW/PROG_SYNOP') )
) t
where rownum = 1;
insert into t1 values(l_clob);
end;
/
Even this gives internal error after 50 minutes.
I have a decent configuration for this test only.
SQL>show sga
Total System Global Area 353442876 bytes
Fixed Size 453692 bytes
Variable Size 142606336 bytes
Database Buffers 209715200 bytes
Redo Buffers 667648 bytes
Tempporary tablespace is 500M.
Please advice.
Regards
February 18, 2005 - 8:45 am UTC
3113, 7445, 600 -> please contact support.
xsql and putXML
Nilanjan Ray, March 02, 2005 - 4:40 am UTC
Does xsql and putXML use the DOM parser internally?
Regards
using sql*loader to load xml data
Nilanjan Ray, March 03, 2005 - 3:56 am UTC
Hi Tom,
Going back to your previous reply about using loader to load xml data. Further the documentation (</code>
http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96621/adx01bas.htm#1011989 <code> also speaks of the same thing. I was trying out the following test. But failed to do it properly.
i am on microsoft windows platform
XML file:-
<?xml version = '1.0' encoding = 'UTF-8'?>
<ROWSET>
<ROW>
<CONTRACT_NO>22251</CONTRACT_NO>
<EPISODE_NO>1</EPISODE_NO>
</ROW>
<ROW>
<CONTRACT_NO>22251</CONTRACT_NO>
<EPISODE_NO>1</EPISODE_NO>
</ROW>
</ROWSET>
Control file:-
LOAD DATA
INFILE 'e:\xmldata\tx1.xml' "str '</ROW>\r\n'"
INTO TABLE tx1
FIELDS TERMINATED BY whitespace
(CONTRACT_NO char(255) ENCLOSED BY "<CONTRACT_NO>" and "</CONTRACT_NO>",
EPISODE_NO char(255) ENCLOSED BY "<EPISODE_NO>" and "</EPISODE_NO>" )
Issuing the follwoing command :
sqlldr userid=stowner/stowner control=e:\xmldata\ctrl.ctl log=e:\xmldata\tx1.log bad=e:\xmldata\tx1.bad
The log file says:
SQL*Loader: Release 9.2.0.1.0 - Production on Tue Dec 28 20:11:48 2004
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Control File: e:\xmldata\ctrl.ctl
Data File: e:\xmldata\tx2.xml
File processing option string: "str '</ROW>\r\n'"
Bad File: e:\xmldata\lob.bad
Discard File: none specified
(Allow all discards)
Number to load: ALL
Number to skip: 0
Errors allowed: 50
Bind array: 64 rows, maximum of 256000 bytes
Continuation: none specified
Path used: Conventional
Table TX1, loaded from every logical record.
Insert option in effect for this table: INSERT
Column Name Position Len Term Encl Datatype
------------------------------ ---------- ----- ---- ---- ---------------------
CONTRACT_NO FIRST 255 CHARACTER
First enclosure string : '<CONTRACT_NO>'
Second enclosure string : '</CONTRACT_NO>'
EPISODE_NO NEXT 255 CHARACTER
First enclosure string : '<EPISODE_NO>'
Second enclosure string : '</EPISODE_NO>'
Record 1: Rejected - Error on table TX1, column CONTRACT_NO.
Initial enclosure character not found
Table TX1:
0 Rows successfully loaded.
1 Row not loaded due to data errors.
0 Rows not loaded because all WHEN clauses were failed.
0 Rows not loaded because all fields were null.
......
I am stuck...A few minutes of your valuable time would help me out to sort out the error.
Thanks & Regards
March 03, 2005 - 7:50 am UTC
the problem is -- it is looking for <contract_no> to be "at the beginning of the line".
not, in the middle somewhere, it is saying "the initial enclosure you told me about, not seeing it"
You would generally load the XML and use the API's in the database to extract what you need from the XML
As per your suggestion I tried using database APIs for xml
Nilanjan Ray, March 03, 2005 - 8:04 am UTC
Thanks Tom for the prompt help.
This is what I tried using XMLType:
CREATE TABLE XMLTABLE OF XMLType;
INSERT INTO XMLTABLE VALUES (XMLType(getDocument('a55_episode.xml')));
This SQL works fine
SELECT extractValue(value(t),'/ROW/CONTRACT_NO') cnt_no,
extractValue(value(t),'/ROW/EPISODE_TITLE') ept ,
extractValue(value(t),'/ROW/PROG_BOARD_CATG_CD') bd
FROM XMLTABLE X,
TABLE ( xmlsequence (
extract(value(X),
'/ROWSET/ROW')
)
) t
/
The problem is one of the tag is CLOB. when ever I try something like
insert into T1
SELECT extractValue(value(t),'/ROW/PROG_SYNOP') pg
FROM XMLTABLE X,
TABLE ( xmlsequence (
extract(value(X),
'/ROWSET/ROW')
)
) t
/
it says:-
insert into T1
*
ERROR at line 1:
ORA-03113: end-of-file on communication channel
Please suggest a way to retrive a clob out of the XML and insert it into a relational table.
Thanks for your precious time.
Regards
March 03, 2005 - 8:08 am UTC
ora 3113, 7445, 600 => please contact support.
A reader, April 21, 2005 - 10:18 am UTC
Sean,
I am refering to your response at the top of this thread.
"
It's failing because you're trying to load a BFILE into a UTF-8 database.
Oracle is reading the file and the file's not UTF-8, therefore Oracle doesn't
recognize the data as being XML. I tried your code above and it works fine in a
standard CHARSET 9i database. (one problem with your XML, DOB had to be
"30/01/1975 0:0:0").
If you want to pursue the BFILE approach, I'd say that's a support issue. Call
Oracle support and send them your test case.
"
I am having the same problem that is mentioned here. THe wokring program has started gicing error after the database character set was upgraded to UTF-8.
In order to pursue BFILE approach, is it not possible to convert file in UTF-8 format? Will it solve the problem?
My file is being created using xmldom.writeToFile. after applying stylesheet to existing file.
Please tell me how do I know which format is my file in. The file is on unix box.
Thanks!
Help with Debuging
Phil, September 20, 2005 - 9:50 am UTC
Hi Tom
XML is hard enough to debug but when something does go wrong I don't even seem to have the trusty dbms_output.put_line at my disposal.
How can I try and debug the following
for SampleXML in(
select
extractvalue(vSuperQryTranslationSamp, '/ValueOne') ValueOne,
extractvalue(vSuperQryTranslationSamp, '/ValueTwo') ValueTwo
from dual) loop
when the sampleXML (XMLTYPE) is or should be NULL and yet the loop is entered!?
Surely, there is a dbms_output type of facility or type conversion to get the SampleXML into a varchar2 chunk?
September 21, 2005 - 1:21 pm UTC
don't know what you mean - do you have a full example?
samplexml is just a cursor - it has two attributes valueone and valuetwo?
Debug
Micaheal, September 21, 2005 - 3:58 am UTC
Yes - this would be useful! Please post a solution
September 21, 2005 - 7:10 pm UTC
I don't know what to post, i don't have "your stuff"
Solution but not for XMLTYPE
A reader, September 21, 2005 - 4:18 am UTC
A reader, April 06, 2006 - 11:44 am UTC
Hi Tom,
I have a file which contains xml data like the following
<?xml version="1.0" ?>
<PickListDef>
<PickList name="reject_pl">
<Item>
1
<Description>Too Dark</Description>
</Item>
<Item>
2
<Description>Too Light</Description>
</Item>
<Item>
3
<Description>Streaked</Description>
</Item>
<Item>
4
<Description>Centering</Description>
</Item>
<Item>
5
<Description>Other</Description>
</Item>
</PickList>
<PickList name="fingerprintOverride_pl">
<Item>
99
<Description>Other</Description>
</Item>
</PickList>
</PickListDef>
I need to load this into a table. In addition to the code and description I also want to insert the value in name like "fingerprintOverride_pl" into a table. Please suggest a solution for that.
Thanks.
Ampersand causes Java error
Rod West, July 21, 2006 - 8:43 am UTC
Tom,
We use Apex to download and upload XML into tables. All works fine until the data contains an & then insertXML throws an exception as shown below. What is the work around for this?
SQL> create table rw_test (col1 varchar2(2000));
Table created.
SQL> set def off
SQL> declare
2 l_ctx dbms_xmlsave.ctxType;
3 l_rows integer;
4 l_clob CLOB ;
5
6 begin
7 DBMS_LOB.createtemporary(l_clob,TRUE);
8 l_clob := '<?xml version = ''1.0''?>
9 <ROWSET>
10 <ROW ROWNUM="1">
11 <COL1>HELLO & WORLD</COL1>
12 </ROW>
13 </ROWSET>';
14
15 l_ctx := dbms_xmlsave.newcontext('RW_TEST');
16 l_rows := dbms_xmlsave.insertXML(l_ctx, l_clob );
17 dbms_xmlsave.closeContext(l_ctx);
18
19 DBMS_LOB.freetemporary(l_clob);
20
21 end;
22 /
declare
*
ERROR at line 1:
ORA-29532: Java call terminated by uncaught Java exception:
oracle.xml.sql.OracleXMLSQLException: Expected name instead of .
ORA-06512: at "APPS.DBMS_XMLSAVE", line 91
ORA-06512: at line 16
July 23, 2006 - 7:25 am UTC
problem is & is not valid in XML - that hello & world is NOT valid xml, it is "garbage"
& must be encoded using the proper entity - &
Just like it must be in HTML
</code>
http://www.xml.com/pub/a/2001/01/31/qanda.html <code>
just like <, >, quotes and other stuff.
Ampersand in XML
Rod West, July 23, 2006 - 10:12 am UTC
Tom,
OK thanks, but is there any utility to turn the data into "proper" XML when it is downloaded from an Apex report?
July 23, 2006 - 10:46 am UTC
this would be a bug in APEX if it did not escape the data I believe (please ask around on the forums on otn.oracle.com...)
If you have control over the query - a htf.escape_sc(column_name) would do it (you could always use a view to have it properly escaped as well)
Loading XML file to a table via DBMS_XMLSave.insertXML
Suresh, July 27, 2006 - 6:04 am UTC
When we generate an XML file including the schema using DBMS_XMLQuery.GetXML(v_ctx,2), which functions are available in oracle that can be used to import the above XML file to a schema where the table doesnt exists.
July 27, 2006 - 11:56 am UTC
eh? if the table doesn't exist, how could you import anything?
XML data file format to load into Oracle Tables
Laxman Kondal, September 20, 2006 - 3:54 pm UTC
Hi Tom
I read few articals and xml book but not able to figure out what xml file format is required for data to be loaded into Oracle10g table. All examples I saw are:
<?xml version = '1.0'?>
<ROWSET>
<ROW num="1">
<EMPNO>7369</EMPNO>
<ENAME>SMITH</ENAME>
<JOB>CLERK</JOB>
<MGR>7902</MGR>
<HIREDATE>12/17/1980 0:0:0</HIREDATE>
<SAL>800</SAL>
<DEPTNO>20</DEPTNO>
</ROW>
<ROW num="2">
------
What if xml data file is like:
<Ports>
<Port><State_Name>Alabama</State_Name><Port_Name>DAUPHIN ISLAND</Port_Name></Port>
<Port><State_Name>Alabama</State_Name><Port_Name>Mobile</Port_Name></Port>
<Port><State_Name>Alabama</State_Name><Port_Name>MOBILE BAR</Port_Name></Port>
<Port><State_Name>Alabama</State_Name><Port_Name>SAND ISLAND</Port_Name></Port>
-------
I did few test loading with first type of xml data file and it works:
l_ctx := dbms_xmlsave.newcontext(i.tname);
--
l_rows := dbms_xmlsave.insertxml(l_ctx, i.theclob);
--
dbms_xmlsave.closecontext(l_ctx);
Is there any way to load xml data from file like:
<Ports>
<Port><State_Name>Alabama</State_Name><Port_Name>DAUPHIN ISLAND</Port_Name></Port>
<Port><State_Name>Alabama</State_Name><Port_Name>Mobile</Port_Name></Port>
<Port><State_Name>Alabama</State_Name><Port_Name>MOBILE BAR</Port_Name></Port>
<Port><State_Name>Alabama</State_Name><Port_Name>SAND ISLAND</Port_Name></Port>
-----
We are looking for automated data loading into Oracle as and when xml data file is received.
Is it possible for the user sending this xml data file to be of certain format which can be loaded without formating.
Thanks and regards.
September 21, 2006 - 1:52 am UTC
you simply need a well formed xml document that conforms to the standard.
Yours does not by the way - there is no closing </ports> tag.
XML data file format to load into Oracle Tables
Laxman Kondal, September 21, 2006 - 7:55 am UTC
Hi Tom
Thanks for reply.
Please if you don't mind where can I find examples which conforms to the standard for loading xml file data into Oracle and are they requirs any change for loading data or Oracle process is same for all.
The example in my case do have closing tag but I just copied from top to paste.
<Port><State_Name>Wisconsin</State_Name><Port_Name>Washburn</Port_Name></Port>
<Port><State_Name>Wisconsin</State_Name><Port_Name>WashburnCounty</Port_Name></Port>
</Ports>
This file has two columns state_name and port_name and the table name ports.
Whats is mising here for 'well formed' document to load into table. I am not sure what tool is being used to generate these xml files and what can we tell them to use particular formate type to generate well formed file.
Thanks and regards.
September 22, 2006 - 1:51 am UTC
you just need to have "standard XML". XML that conforms to the standards for XML.
nice thread, am also having difficulty inserting multilevel xml into a table
Kevin from CT, October 14, 2006 - 5:48 pm UTC
I am also having a problem inserting xml when the xml contain multiple levels of object types. I am trying to understand how this works. Here is my sample case:
dept has employees, employees have timesheets.
An object view with instead of trigger creates a row driven by dept containing an employee list collection, each employee of which contains a timesheet collection.
Here is all the code and the error. If I only do dept and emp it works fine, but when I add the next layer down (ie the timesheet), it fails.
You will notice that the anonymous pl/sql block is simply trying to insert a record that it just selected. I figured if I can't do this simple thing I must be doing something wrong or there must be a limitation I am hitting.
The code below will select a row off the object view using dbms_xmlgen.getxml, delete the underlying data, and then reinsert the row using dbms_xmlsave.
declare
*
ERROR at line 1:
ORA-29532: Java call terminated by uncaught Java exception:
oracle.xml.sql.OracleXMLSQLException: 'The XML element tag 'TIMESHEET_LIST'
does not match the name of any of the columns/attributes of the target database
object.' encountered during processing ROW element 0. All prior XML row
changes were rolled back. in the XML document.
ORA-06512: at "SYS.DBMS_XMLSAVE", line 115
ORA-06512: at line 17
create table dept (
dno number not null
,dname varchar2(30) not null
)
/
alter table dept
add primary key (dno)
add unique (dname)
/
create table emp (
eno number not null
,ename varchar2(30) not null
,dno number not null
)
/
alter table emp
add primary key (eno)
add unique (ename)
add foreign key (dno) references dept
/
create table timesheet (
tno number
,tweek date
,eno number
)
/
alter table timesheet
add primary key (tno)
add unique (tweek,eno)
add foreign key (eno) references emp
/
insert into dept values (3,'D3');
insert into emp values (37,'Jay',3);
insert into emp values (38,'Jim',3);
insert into timesheet values (221,sysdate,37);
insert into timesheet values (222,sysdate-7,37);
insert into timesheet values (223,sysdate,38);
insert into timesheet values (224,sysdate-7,38);
commit
/
create or replace
type o_timesheet is object (
tno number
,tweek varchar2(30)
,eno number
)
/
create or replace
type c_timesheet is table of o_timesheet
/
create or replace
type o_emp is object (
eno number
,ename varchar2(30)
,dno number
,timesheet_list c_timesheet
)
/
create or replace
type c_emp is table of o_emp
/
create or replace
view vw_xml_dept
as
select dept.*
,cast(multiset(
select emp.*
,cast(multiset(
select timesheet.*
from timesheet
where timesheet.eno = emp.eno
) as c_timesheet) timesheet_list
from emp
where emp.dno = dept.dno
order by eno desc
) as c_emp) emp_list
from dept
/
select dbms_xmlgen.getxml('select * from vw_xml_dept') xmldata
from dual
/
XMLDATA
---------------------------------------------
<?xml version="1.0"?>
<ROWSET>
<ROW>
<DNO>3</DNO>
<DNAME>D3</DNAME>
<EMP_LIST>
<O_EMP>
<ENO>38</ENO>
<ENAME>Jim</ENAME>
<DNO>3</DNO>
<TIMESHEET_LIST>
<O_TIMESHEET>
<TNO>223</TNO>
<TWEEK>14-OCT-06</TWEEK>
<ENO>38</ENO>
</O_TIMESHEET>
<O_TIMESHEET>
<TNO>224</TNO>
<TWEEK>07-OCT-06</TWEEK>
<ENO>38</ENO>
</O_TIMESHEET>
</TIMESHEET_LIST>
</O_EMP>
<O_EMP>
<ENO>37</ENO>
<ENAME>Jay</ENAME>
<DNO>3</DNO>
<TIMESHEET_LIST>
<O_TIMESHEET>
<TNO>221</TNO>
<TWEEK>14-OCT-06</TWEEK>
<ENO>37</ENO>
</O_TIMESHEET>
<O_TIMESHEET>
<TNO>222</TNO>
<TWEEK>07-OCT-06</TWEEK>
<ENO>37</ENO>
</O_TIMESHEET>
</TIMESHEET_LIST>
</O_EMP>
</EMP_LIST>
</ROW>
</ROWSET>
create or replace
trigger ioi_vw_xml_dept
instead of insert on vw_xml_dept
for each row
begin null;
insert into dept values (:new.dno,:new.dname);
for i in 1..nvl(:new.emp_list.count,0) loop null;
insert into emp values (
:new.emp_list(i).eno
,:new.emp_list(i).ename
,:new.emp_list(i).dno
);
for j in 1..nvl(:new.emp_list(i).timesheet_list.count,0) loop
insert into timesheet values (
:new.emp_list(i).timesheet_list(j).tno
,:new.emp_list(i).timesheet_list(j).tweek
,:new.emp_list(i).timesheet_list(j).eno
);
end loop;
end loop;
end;
/
show errors
declare
v_xml clob;
begin
select dbms_xmlgen.getxml('select * from vw_xml_dept') xmldata
into v_xml
from dual
;
delete from timesheet;
delete from emp;
delete from dept;
declare
insCtx DBMS_XMLSave.ctxType;
rows number;
begin
insCtx := DBMS_XMLSave.newContext('vw_xml_dept'); -- get the context handle
DBMS_XMLSave.SetIgnoreCase(insCtx,1);
rows := DBMS_XMLSave.insertXML(insCtx,v_xml); -- this inserts the document
DBMS_XMLSave.closeContext(insCtx); -- this closes the handle
end;
end;
/
Thanks, Kevin
never mind, TAR showed it was my stupidity
A reader, October 18, 2006 - 12:20 am UTC
I needed to reboot my oracle instance (not sure why). It works now. Thanks, Kevin
Select on View with "Table of XMLTYPE"
Rory, February 12, 2007 - 9:14 pm UTC
Hi Tom,
How do I query the contents of the view "CPU_XML" below.
I think it contains xml data.
Pls help me output it in the proper formatting.
Thanks.
SQL> desc itiread.cpu_xml
Name Null? Type
----------------------------------------- -------- ----------------------------
TABLE of XMLTYPE
SQL> select owner,object_name,object_type
2 from dba_objects where object_name='CPU_XML';
OWNER OBJECT_NAME OBJECT_TYPE
---------- ------------------------------ ------------------
ITIREAD CPU_XML VIEW
SQL> l
1 select text from dba_views
2* where view_name='CPU_XML'
select
XMLELEMENT
(
"computers",
XMLAGG
(
XMLELEMENT
(
"computer",
XMLATTRIBUTES(computerid as "id"),
XMLForest
(
assettag as "assettag",
hostname as "hostname",
modelfullname as "model",
modelno as "modelno",
serialno as "serialno",
location as "location",
startu as "startu",
get_assignment(seassignment) as "assignment",
serverstatus as "serverstatus"
)
)
)
)
from select_all_cpu
where systemtype='Server'
SQL> set long 1000000
SQL> /
select
XMLELEMENT
(
"computers",
XMLAGG
(
XMLELEMENT
(
"computer",
XMLATTRIBUTES(computerid as "id"),
XMLForest
(
assettag as "assettag",
hostname as "hostname",
modelfullname as "model",
modelno as "modelno",
serialno as "serialno",
location as "location",
startu as "startu",
get_assignment(seassignment) as "assignment",
serverstatus as "serverstatus"
)
)
)
)
from select_all_cpu
where systemtype='Server'
As you can see below, a select on the view outputs only the following. How can I generate the whole output with the proper formatting.
Thanks.
SQL> select * from itiread.cpu_xml;
SYS_NC_ROWINFO$
--------------------------------------------------------------------------------
<computers><computer id="14178708"><assettag>107459</assettag><hostname>ACVACTID
Load Nested XML into tables
Karmit, May 21, 2008 - 6:07 am UTC
I have an XML file from one of our suppliers.
The data is nested up to 5 levels. I can see the same XML tag appear in more then one place.
Following is a short example of the XML. Here the <PARTY_INFO> group appears twice, each time under different group, same for <VAT> tag.
When I'm trying to load the XML data into the table, I get an error:
ORA-29532: Java call terminated by uncaught Java exception: oracle.xml.sql.OracleXMLSQLException: Exception ' The XML element tag 'COUNTRY' does not match the name of any of the columns/attributes of the target database object.' encountered during processing ROW element 0All prior XML row changes were rolled back. in the XML document.
create type xxil_PartyInfoType AS OBJECT
(
PARTY_NAME varchar2 (100),
STREET varchar2(100),
POB varchar2(10),
CITY varchar2(100),
ZIP varchar2(10),
STATE varchar2(100),
COUNTRY varchar2(3)
);
create type xxil_ToAddressType AS OBJECT
(
PARTY_INFO xxil_PartyInfoType ,
ACC_NO varchar2(7),
VAT varchar2(9)
);
CREATE TYPE xxil_ToAddrTable AS TABLE OF xxil_ToAddressType;
create type xxil_ByAddressType AS OBJECT
(
PARTY_INFO xxil_PartyInfoType ,
VAT varchar2(9)
);
CREATE TYPE xxil_ByAddrTable AS TABLE OF xxil_ByAddressType;
CREATE TABLE xxilxml_test
(
TO_ADR xxil_ToAddrTable,
BY_ADR xxil_ByAddrTable
)
nested table TO_ADR store as TO_ADR_NestTab
nested table BY_ADR store as BY_ADR_NestTab
;
declare
v_xml clob;
l_ctx dbms_xmlsave.ctxType;
l_rows number;
begin
v_xml :=
'<DATA>
<ROW>
<TO_ADR>
<PARTY_INFO>
<PARTY_NAME>NAME1</PARTY_NAME>
<STREET>5th. Eve</STREET>
<POB>34</POB>
<CITY>City Name</CITY>
<ZIP>12345</ZIP>
<STATE>NY</STATE>
<COUNTRY>USA</COUNTRY>
</PARTY_INFO>
<ACC_NO>1-234-5</ACC_NO>
<VAT>14.5</VAT>
</TO_ADR>
<BY_ADR>
<PARTY_INFO>
<PARTY_NAME>MY_NAME</PARTY_NAME>
<STREET>My St.</STREET>
<POB>11</POB>
<CITY>My City</CITY>
<ZIP>98765</ZIP>
<STATE>OH</STATE>
<COUNTRY>USA</COUNTRY>
</PARTY_INFO>
<VAT>14.5</VAT>
</BY_ADR>
</ROW>
<ROW>
<TO_ADR>
<PARTY_INFO>
<PARTY_NAME>NAME2</PARTY_NAME>
<STREET>New St.</STREET>
<POB>68</POB>
<CITY>Town Name</CITY>
<ZIP>54321</ZIP>
<STATE>NJ</STATE>
<COUNTRY>USA</COUNTRY>
</PARTY_INFO>
<ACC_NO>1-432-5</ACC_NO>
<VAT>14.5</VAT>
</TO_ADR>
<BY_ADR>
<PARTY_INFO>
<PARTY_NAME>MY_NAME</PARTY_NAME>
<STREET>My St.</STREET>
<POB>11</POB>
<CITY>My City</CITY>
<ZIP>98765</ZIP>
<STATE>OH</STATE>
<COUNTRY>USA</COUNTRY>
</PARTY_INFO>
<VAT>14.5</VAT>
</BY_ADR>
</ROW>
</DATA>';
l_ctx := dbms_xmlsave.newContext('XXILXML_TEST');
dbms_xmlsave.setignorecase(l_ctx,1);
l_rows := dbms_xmlsave.insertxml(l_ctx, v_xml);
dbms_xmlsave.closeContext(l_ctx);
dbms_output.put_line(l_rows || ' rows inserted...');
END;
How can I load the XML data into a table when I have duplicate tags?
Thanks in advance,
Karmit