Solved

load xml file with SQL Loader

Posted on 2012-03-30
11
2,360 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

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

Expert Comment

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

I mis-read ALL the time!
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Oracle encryption 12 72
Oracle database T-1 Setup 7 45
Oracle Errors 11 89
Select the 2 most recent visit dates 5 31
Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

734 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