表aa(a,b,c,d)
表bb(a,b)
现在要把aa 表插入一条数据,a,b字段从表bb获得,c,d作为参数输入,不用存储过程在oracle里怎么写

解决方案 »

  1.   


    SQL> select * from a;                                      A                                       B                                       C                                       D
    --------------------------------------- --------------------------------------- --------------------------------------- ---------------------------------------SQL> select * from b;                                      A                                       B
    --------------------------------------- ---------------------------------------
                                          1                                       1
                                          2                                       2
                                          3                                       3
                                          4                                       4SQL> insert into a select a,b,8888,9999 from b;4 rows insertedSQL> select * from a;                                      A                                       B                                       C                                       D
    --------------------------------------- --------------------------------------- --------------------------------------- ---------------------------------------
                                          1                                       1                                    8888                                    9999
                                          2                                       2                                    8888                                    9999
                                          3                                       3                                    8888                                    9999
                                          4                                       4                                    8888                                    9999SQL> 
      

  2.   

    insert into aa (a,b,c,d)
    select (a,b,参数c,参数d)
    from bb where 
      

  3.   

    第一步:
    insert into aa(a,b)
    select (a,b)
      from bb
     where ....第二步:
    update aa 
       set c = &c
       and d = &d
     where a = (select a from bb where...)
       and b = (select b from bb where...)