multi-table insert in Oracle 9i

Ask a Question related to Oracle Server, Design and Development.

  1. #1

    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;


    Niloufar Guest

  2. Similar Questions and Discussions

    1. #40787 [NEW]: Error trying to insert into a CLOB column when using multi-byte charset.
      From: jarismar at adplabs dot com dot br Operating system: PHP version: 5.2.1 PHP Bug Type: PDO related Bug description: ...
    2. Oracle Table Access With Oracle OLEDB Driver
      If I use the Oracle client to access the Oracle database with DW 2004, it does not display any tables. If I use the Microsoft client it does work. ...
    3. How Do you insert a table in Previous Table
      How Do you insert a table in Previous Table that has an image, in a web page
    4. Login - multi table insert for registrant; subsquent login insert page requests into joined 'Selection' Table
      Question regards insert and updates in sql server for a simple login script that requires registration the first time and only "email address" upon...
    5. How to insert multiple records to the same table with a multi-fields form
      Hi all, is it possibile to insert multiple records in the same table? I imagine to build a multi-rows form, with the same number of fields per...
  3. #2

    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;
    >
    >
    Dave Hau Guest

  4. #3

    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;
    >>
    >>
    >
    Niloufar Guest

  5. #4

    Thumbs up Re: multi-table insert in Oracle 9i

    right answer is this
    for single table
    SQL> insert all when 1=1 then
    2 into junk (id, order_num,bill_amt)
    3 select order_id, order_number,bill_amt from junk_input;


    for multitable
    SQL> insert all when 1=1 then
    2 into junk (id, order_num,bill_amt)
    3 when order_number = '5678' then
    4 into junk2 (id2, order_num2,bill_amt2)
    5 select order_id, order_number,bill_amt from junk_input;
    shonali Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139