oracle数据库 用语句向多个表中插入一列。

解决方案 »

  1.   

    Most INSERT statements are the single-table variety, 
    but Oracle also supports a multiple-table INSERT statement. 
    With a multitable insert, you can make a single pass 
    through the source data and load the data into more than one table. insert [ ALL | FIRST ] 
    WHEN condition THEN insert_into_clause [values_clause] 
    [insert_into_clause [values_clause]]... 
    [WHEN condition THEN insert_into_clause [values_clause] 
    [insert_into_clause [values_clause]]... 
    ]... 
    [ELSE insert_into_clause [values_clause] 
    [insert_into_clause [values_clause]]... 
    ] If a WHEN condition evaluates to TRUE, the corresponding INTO clause is executed. 
    If no WHEN condition evaluates to TRUE, the ELSE clause is executed. 
    The keyword ALL tells the database to check each WHEN condition. On the other hand, 
    the keyword FIRST tells the database to stop checking WHEN conditions after finding the first TRUE condition.an example:
    SQL> truncate table test;
     
    Table truncated
     
    SQL> truncate table test1;
     
    Table truncated
     
    SQL> 
    SQL> insert first
      2  when 1=1 then into test(id)
      3  else into test1(seq_no)
      4  select 1 from dual
      5  ;
     
    1 row inserted
     
    SQL> select * from test;
     
             ID NAME
    ----------- --------------------------------------------------------------------------------
              1 
     
    SQL> select * from test1;
     
         SEQ_NO TYPE1 TYPE2          AMT MARK
    ----------- ----- ----- ------------ ------
     
    SQL> 
      

  2.   

    --用insert all(first)
    insert all
    when condition1 then into table1
    when condition2 then into table2
    else into table3
    select * from tablename