用oracle SQL 写一个查询结果集后 用结果集循环 并用结果集的列做if条件 满足条件后用结果集的列进行批量插select n1,n2 from t1 where 1=1
for(上面的结果集){
    if(n1==x){
        insert into t2 value (n2,xx)        insert into t2 value (n2,xx1)        insert into t2 value (n2,xx2)        insert into t2 value (n2,xx3)    }
}
大概就是这个意思 只是用SQL表示出来
本人分少 高抬贵手

解决方案 »

  1.   

    你的描述就有问题,既然xx1,xx2等在一个循环中,他就应该是个变量,或者是一个定值
      

  2.   

    一个简单的例子,做适当修改就好
    declare
      cursor s_cur is
        select * from s;
    begin
      for r in s_cur loop
        if r.s_id > 0 then
          insert into s3 values (r.s_id, r.S_name);
        end if;
      end loop;
    close   s_cur;
      commit;
    end;
      

  3.   


    declare
      cursor s_cur is
        select n1,n2 from t1;
    begin
      for r in s_cur loop
        if r.n1 ='x' then
          insert into t2 values (r.n2, 'xx');
        end if;
      end loop;
      commit;
    end;
      

  4.   

    declare cursor s_card is 
    select cp.par_value,
           ct.code || '_' || cp.par_value codeValue
      from t_card_type ct, t_card_parvalue cp
     where ct.card_category_id in (1, 2)
       and cp.card_type_id = ct.id
       and cp.par_value in (100, 200, 300, 500, 100);
    begin
      for card in s_card loop
        if card.par_value = 100 then
          insert into t_card_sysbook values (seq_t_card_sysbook.nextval, 'CARD_STYLE', '福', card.codeValue, 1, '福', sysdate, null, null, null);
          insert into t_card_sysbook values (seq_t_card_sysbook.nextval, 'CARD_STYLE', '禄', card.codeValue, 1, '禄', sysdate, null, null, null);
          insert into t_card_sysbook values (seq_t_card_sysbook.nextval, 'CARD_STYLE', '寿', card.codeValue, 1, '寿', sysdate, null, null, null);
          insert into t_card_sysbook values (seq_t_card_sysbook.nextval, 'CARD_STYLE', '喜', card.codeValue, 1, '喜', sysdate, null, null, null);
        end if;
      end loop;
      close s_card;
      commit;
    end;违反了t_card_sysbook 的主键唯一约束 在seq_t_card_sysbook.nextval获取序列的时候难道不COMMIT之前都是取的一样的?
      

  5.   

    insert into a(col1,col2) select b.b1,b.b2 from b where b1= xxx  
      

  6.   

    close s_card; 
    把这一句去掉