Home » SQL & PL/SQL » SQL & PL/SQL » 2 tables, different formats, extract to csv.
2 tables, different formats, extract to csv. [message #21812] Mon, 02 September 2002 00:49 Go to next message
Mike
Messages: 417
Registered: September 1998
Senior Member
hi,
could anyone tell me how to achive the following using
sql plus.
if we have 2 tables, with different formats,
for example the following.

TABLE A (Header)
key Data
1 D1
2 D2
3 D3

TABLE B (Line)
key Data1 Data2
1 F 1
1 G 2
2 H 3
2 I 4
3 J 5

We would want the data to appear as follows in the file.
1, D1
1, F, 1
1, G, 2
2, D2
2, H, 3
2, I, 4 etc.

this needs a cursor as far as I can see - can this be implemented in a sql plus extract? I can't get the cursor to print out the rows to the screen so I can spool this in sql plus.

appreciate any help.
Re: 2 tables, different formats, extract to csv. [message #21814 is a reply to message #21812] Mon, 02 September 2002 12:48 Go to previous message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
Mike, I had answered a similar question you posted in the other forum:

http://www.orafaq.net/msgboard/newbies/messages/4002.htm

Here, you have changed the data slightly.

select key || ',' || data
  from table_a
union
select key || ',' || data1 || ',' || data2
  from table_b
order by 1;


Just run this query in SQL*Plus with spooling on.
Previous Topic: Whether to use Cursors or Update Queries
Next Topic: Re: Database trigger
Goto Forum:
  


Current Time: Tue May 07 06:02:45 CDT 2024