tags:

views:

169

answers:

1

I have a dump of several Postgresql Tables in a selfcontained CSV file which I want to import into an Oracle Database with a matching schema. I found several posts on how to distribute data from one CSV "table" to multiple Oracle tables, but my problem is several DIFFERENT CVS "tables" in the same file.

Is it possible to specify table separators or somehow mark new tables in an SQLLDR control file, or do I have to split up the file manually before feeding it to SQLLDR?

+2  A: 

That depends on your data. How do you determine which table a row is destined for? If you can determine which table base on data in the row, then it is fairly easy to do with a WHEN.

LOAD DATA
  INFILE bunchotables.dat
INTO TABLE foo WHEN somecol = 'pick me, pick me' (
  ...column defs...
)
INTO TABLE bar WHEN somecol = 'leave me alone' (
  ... column defs
)

If you've got some sort of header row that determines the target table then you are going to have to split it before hand with another utility.

Scott Bailey
+1 this should do it.
DCookie
Yes, that sounds good - does something like this also work for single markers between tables? The format I get looks something like this:COPY foo (foo_1, foo_2) FROM stdin;1 2\.COPY bar (bar_1, bar_2) FROM stdin;1 2\.
VolkA
No, as I said, sqlldr is not going to handle single markers between tables. You'll need to write a Perl/Python/Ruby/whatever script to scan your source file and split them into 1 file per table. That should be pretty easy to do. But you didn't really give us enough info to help you with that.
Scott Bailey
Oh yeah, reading the complete post before commenting helps :) Thanks for the answer and cheers!
VolkA