参数配置表SQL语句求解,谢谢 
我定义了一个参数表,但现在条件变动很厉害,改动很大,一条条插入明显很慢...希望通过PL/SQL简化工作量...但对SQL语句用的不好,望网上的朋友指点一下,谢谢
有一个表A,里面有一个code,type_id,acct_type_id三个字段;
如以前里面有记录如下:
code type_id acct_type_id
a01 22            36
a01 27            36
a01 1804          36
a01 22            42
a01 27            42
a01 1804          42
现在acct_type_id有变动,需要修改,acct_type_id的值来源于
select b.acct_type_id from d_type b, d_item c
where b.stat_item_id=c.stat_item_id
and c.name like 're%'
将上面的SQL语句结果acct_type_id值插入到表A中,
type_id有几种,acct_type_id插入就几次;
假如上面的语句出来的acct_type_id是35,41,46,47,50,68;则结果如下
code type_id acct_type_id
a01 22 35
a01 27 35
a01 1804 35
a01 22 41
a01 27 41
a01 1804 41
a01 22 46
a01 27 46
a01 1804 46
a01 22 47
a01 27 47
a01 1804 47
a01 22 50
a01 27 50
a01 1804 50
a01 22 68
a01 27 68
a01 1804 68 
使用怎样的SQL语句可以得到以上结果.....如果type_id很多;

解决方案 »

  1.   

    insert all 
      when 1=1 then  
          insert into A valus('a01','22',acct_type)
      when 1=1 then  
          insert into A valus('a01','27',acct_type)
       when 1=1 then  
          insert into A valus('a01','1804',acct_type)select b.acct_type_id from d_type b, d_item c
    where b.stat_item_id=c.stat_item_id
    and c.name like 're%'
      

  2.   

    insert into 表A
    (code,
    type_id,
    acct_type_id)
    (select a.code,
           a.type_id,
           b.acct_type_id 
    from d_type b, 
    d_item c ,
    (select distinct code type_id from 表A ) a
    where b.stat_item_id=c.stat_item_id
    and c.name like 're%'
    )