Solved

load xml file with SQL Loader

Posted on 2012-03-30
11
1,986 Views
Last Modified: 2012-03-30
Experts,

I want to import an XML file into Oracle using SQL Loader and then extract data once it's loaded. I've found some examples but I cant get it to work.

My xml file is -- ReturnFile.xml (I've attached a sample)


CREATE TABLE XML_INPUT
(
RAWXML XMLTYPE
)

My Contol File looks like this:

OPTIONS ( DIRECT=TRUE)
LOAD DATA
INFILE '\\dw2\e$\data\ARDENT\Milliman\Output File\Return_File.xml'


INTO TABLE "JVO0"."XML_INPUT"
APPEND
XMLTYPE
FIELDS TERMINATED BY ','
(
RAWXML LOBFILE(ReturnFile) TERMINATED BY EOF
)


When I run from the command line:

sqlldr jvo0/pw@company direct=true, control=C:\XML.CTL, log=c:\XML.LOG

I get this error:
SQL*Loader-350: Syntax error at line 9.
Expecting "(" , found "XMLTYPE".

Any assistance is appreciated.
ReturnFile.xml
0
Comment
Question by:jvoconnell
  • 6
  • 5
11 Comments
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 37788686
Check the docs:
docs.oracle.com/cd/B28359_01/appdev.111/b28369/xdb25loa.htm#autoId5

I was able to load your file with:

OPTIONS ( DIRECT=TRUE)
LOAD DATA
INFILE *
INTO TABLE TAB1
APPEND
FIELDS TERMINATED BY ','
(
fill filler char(1),
RAWXML LOBFILE(CONSTANT '\\dw2\e$\data\ARDENT\Milliman\Output File\Return_File.xml'
) TERMINATED BY EOF
)
begindata
0
0
 
LVL 1

Author Comment

by:jvoconnell
ID: 37788803
Thank you very much. Do I have to also change the datatype for the column? I get a sql loader error 418-bad datafile datatype for column RAWXML
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 37788811
I used your create table script.  I ran it against 10.2.0.3.

What is your Oracle version (all 4 numbers)?
0
 
LVL 1

Author Comment

by:jvoconnell
ID: 37788823
10.2.0.4
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 37788830
I didn't try it using UNC.  I saved the file to a local disk.

For grins, can you copy the file locally and remove '\\dw2\e$\data\ARDENT\Milliman\Output File\Return_File.xml'?
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 1

Author Comment

by:jvoconnell
ID: 37788883
copying the return_file.xml to the C: and using this syntax in the control still produces the error

OPTIONS ( DIRECT=TRUE)
LOAD DATA
INFILE *
INTO TABLE XML_INPUT
APPEND
FIELDS TERMINATED BY ','
(
fill filler char(1),
RAWXML LOBFILE(CONSTANT 'Return_File.xml'
) TERMINATED BY EOF
)
begindata
0
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 37788930
Is the database you are loading into also 10g or might it be 9i?


askTom actually has a cleaner version and talks about this error but also says it is fixed in 10g.

http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:738791653185

Here is the updated control file base on the askTom link:

OPTIONS ( DIRECT=TRUE)
LOAD DATA
INFILE *
INTO TABLE TAB1
APPEND
FIELDS TERMINATED BY ','
(
lob_file filler char(50),
RAWXML LOBFILE(lob_file) TERMINATED BY EOF
)
begindata
q.txt
0
 
LVL 1

Author Comment

by:jvoconnell
ID: 37789075
Thanks for the help. It really is appreciated. I'm going to keep plugging away.

I looked at the askTom page you sent. I changed the datatype in the table from XMLTYPE to CLOB. THen tried the loader and got an error to use Trailing Null Cols in ctl file. When adding that I received sqlldr error 462 "error inserting LOB into column RAWXML" and error 646 "lob set to empty in column RAWXML"...and I get two empty rows

So it looks like changing the datatype to clob wasn't going down the right path.

I am using 10G but the sql loader is release 9.2.0.1 (i don't know if that has anything to do with it)

Thanks for the time.
0
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 37789197
>>but the sql loader is release 9.2.0.1 (i don't know if that has anything to do with it)


It has everything to do with it.  The askTom article specifically points you to the solution:

That is why I asked it you were going against a 9i database.

Excerpt from the link above:


Followup   June 29, 2004 - 7pm Central time zone:

create tbl_xmlwork( docid number, xmldoc SYS.xmltype );


it is an issue with sqlldr in 9ir2 with the SYNONYM for xmltype -- it got "confused"

it was corrected in 10g
0
 
LVL 1

Author Comment

by:jvoconnell
ID: 37789624
I can't believe I missed that. Very embarrasing. Thank you for the help....again!!!
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 37789735
No problem.  Glad to help.

I mis-read ALL the time!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now