Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

load xml file with SQL Loader

Posted on 2012-03-30
11
Medium Priority
?
2,803 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 77

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 77

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:jvoconnell
ID: 37788823
10.2.0.4
0
 
LVL 77

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
 
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 77

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 77

Accepted Solution

by:
slightwv (䄆 Netminder) earned 2000 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 77

Expert Comment

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

I mis-read ALL the time!
0

Featured Post

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
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 videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

715 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