日期:2014-05-17  浏览次数:20945 次

用oracle SQL 查询结果集 用集循环 并用集的列做if条件 满足条件后集的列批量插
用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表示出来
本人分少 高抬贵手

------解决方案--------------------

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;