Unix Technical Forum

multi-table insert in Oracle 9i

This is a discussion on multi-table insert in Oracle 9i within the Oracle Database forums, part of the Database Server Software category; --> Could someone please tell me what am I doing wrong that causes both of the following multi-table insert statements ...


Go Back   Unix Technical Forum > Database Server Software > Oracle Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-22-2008, 05:55 PM
Niloufar
 
Posts: n/a
Default multi-table insert in Oracle 9i

Could someone please tell me what am I doing wrong that causes both of
the following multi-table insert statements to fail with a "missing key"
error. My Oracle server is Version 9.2.0.2.0.

Thanks,
Niloufar

************************************************** *****************************
create table junk(id number,order_num varchar2(10),bill_amt number);
create table junk2(id2 number,order_num2 varchar2(10),bill_amt2 number);
create table junk_input(order_id number,order_number
varchar2(10),bill_amt number);

insert into junk_input values (1, '1234', 10);
insert into junk_input values (2, '1234', 10);
insert into junk_input values (3, '1234', 10);
insert into junk_input values (4, '5678', 10);
insert into junk_input values (5, '5678', 10);
select * from junk_input;

tried both:

insert all when 1=1
into junk (id, order_num, sequence_num)
select order_id, order_number, seq_num from junk_input;

and tried:

insert all when 1=1
into junk (id, order_num, sequence_num)
when order_number = '5678'
into junk2 (id2, order_num2, sequence_num2)
select order_id, order_number, seq_num from junk_input;


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-22-2008, 05:55 PM
Dave Hau
 
Posts: n/a
Default Re: multi-table insert in Oracle 9i

You're missing a "THEN" keyword:

insert all when 1=1 THEN
into junk (id, order_num, sequence_num) ...

Also, if the condition is 1=1, you don't need to specify it at all:

insert all
into junk (id, order_num, sequence_num) ...

does the same thing.

Cheers,
Dave




Niloufar wrote:
> Could someone please tell me what am I doing wrong that causes both of
> the following multi-table insert statements to fail with a "missing key"
> error. My Oracle server is Version 9.2.0.2.0.
>
> Thanks,
> Niloufar
>
> ************************************************** *****************************
>
> create table junk(id number,order_num varchar2(10),bill_amt number);
> create table junk2(id2 number,order_num2 varchar2(10),bill_amt2 number);
> create table junk_input(order_id number,order_number
> varchar2(10),bill_amt number);
>
> insert into junk_input values (1, '1234', 10);
> insert into junk_input values (2, '1234', 10);
> insert into junk_input values (3, '1234', 10);
> insert into junk_input values (4, '5678', 10);
> insert into junk_input values (5, '5678', 10);
> select * from junk_input;
>
> tried both:
>
> insert all when 1=1
> into junk (id, order_num, sequence_num)
> select order_id, order_number, seq_num from junk_input;
>
> and tried:
>
> insert all when 1=1
> into junk (id, order_num, sequence_num)
> when order_number = '5678'
> into junk2 (id2, order_num2, sequence_num2)
> select order_id, order_number, seq_num from junk_input;
>
>


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-22-2008, 05:56 PM
Niloufar
 
Posts: n/a
Default Re: multi-table insert in Oracle 9i

Thank you Dave.

I feel silly that I didn't pay more attention to the syntax.

However, regarding the "when 1=1" clause, if I have multiple "when"
clauses in the statement, I can not execute it if the first "inert into"
doesn't have a when clause. I get a "missing select keyword" error.

Thanks,
Niloufar

Dave Hau wrote:
> You're missing a "THEN" keyword:
>
> insert all when 1=1 THEN
> into junk (id, order_num, sequence_num) ...
>
> Also, if the condition is 1=1, you don't need to specify it at all:
>
> insert all
> into junk (id, order_num, sequence_num) ...
>
> does the same thing.
>
> Cheers,
> Dave
>
>
>
>
> Niloufar wrote:
>
>> Could someone please tell me what am I doing wrong that causes both of
>> the following multi-table insert statements to fail with a "missing
>> key" error. My Oracle server is Version 9.2.0.2.0.
>>
>> Thanks,
>> Niloufar
>>
>> ************************************************** *****************************
>>
>> create table junk(id number,order_num varchar2(10),bill_amt number);
>> create table junk2(id2 number,order_num2 varchar2(10),bill_amt2 number);
>> create table junk_input(order_id number,order_number
>> varchar2(10),bill_amt number);
>>
>> insert into junk_input values (1, '1234', 10);
>> insert into junk_input values (2, '1234', 10);
>> insert into junk_input values (3, '1234', 10);
>> insert into junk_input values (4, '5678', 10);
>> insert into junk_input values (5, '5678', 10);
>> select * from junk_input;
>>
>> tried both:
>>
>> insert all when 1=1
>> into junk (id, order_num, sequence_num)
>> select order_id, order_number, seq_num from junk_input;
>>
>> and tried:
>>
>> insert all when 1=1
>> into junk (id, order_num, sequence_num)
>> when order_number = '5678'
>> into junk2 (id2, order_num2, sequence_num2)
>> select order_id, order_number, seq_num from junk_input;
>>
>>

>


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:57 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com