Re: SQL Experts Only

From: Naresh Ramamurti <nramamur_at_worldnet.att.net>
Date: 1996/08/06
Message-ID: <32082559.3E6F_at_worldnet.att.net>#1/1


Ken Kennedy wrote:
>
> Here is my dilema...
>
> I have two tables in production that appear as shown below:
>
> SQL> desc TABLE_A
> Name Null? Type
> ------------------------------- -------- ----
> IDENTIFIER_ID NOT NULL NUMBER
> SOME_FIELD_1 VARCHAR2(20)
> SOME_FIELD_2 NUMBER
>
> SQL> desc TABLE_B
> Name Null? Type
> ------------------------------- -------- ----
> IDENTIFIER_ID NOT NULL NUMBER
> FK_TABLE_A_ID NUMBER
> SOME_OTHER_FIELD VARCHAR2(20)
>
> Currently, only TABLE_A is populated and TABLE_B is a new table. I need
> to insert an entry in TABLE_B for each row in TABLE_A. If there are 30
> rows in TABLE_A, I need to insert 30 rows in the new table. The
> IDENTIFIER_ID is a sequence number (SOME_SEQ) and the FK_TABLE_A_ID is a
> foreign key to TABLE_A.IDENTIFIER_ID.
>
> Can I do the update through SQL? I know I can make the update writing a
> quick C++/ODBC application, but I'd rather just use SQL.
>
> Any help is greatly appreciated.
>
> Ken

Try this...

insert into TABLE_B

	select
		SOME_SEQ.NEXTVAL,
		TABLE_A.IDENTIFIER_ID,
		'SOME VALUE'
	from
		TABLE_A
	;

commit;

This should insert 30 rows into TABLE_B...

Naresh. Received on Tue Aug 06 1996 - 00:00:00 CEST

Original text of this message