呵呵,num 是你循环的次数,只是举一个循环的例子 可以不一定是for 循环,也可以是 while 循环,或者是简单的 Loop循环
就用loop循环吧,给个例子看看。 需要实现关键点:如何跳过不符合条件的,操作符合条件的
可以在游标里面过滤掉不符合条件的记录,或者在循环里加上一个判断阿 open csr_cursor_name for 'select * from tab_name where ...' --在打开游标的时候直接过滤掉不符合条件的记录 或者 l_csr csr_cursor_name%rowtype; ... begin open csr_cursor_name ; fetch csr_cursor_name into l_csr; exit when csr_cursor_name%notfound ; if (符合某个条件 = true ) then ... end if; end loop;
ex:
for i in 1 .. num loop
if (符合某个条件 = true ) then
...
end if;
end loop;
可以不一定是for 循环,也可以是 while 循环,或者是简单的 Loop循环
需要实现关键点:如何跳过不符合条件的,操作符合条件的
open csr_cursor_name for 'select * from tab_name where ...' --在打开游标的时候直接过滤掉不符合条件的记录
或者
l_csr csr_cursor_name%rowtype;
...
begin
open csr_cursor_name ;
fetch csr_cursor_name into l_csr;
exit when csr_cursor_name%notfound ;
if (符合某个条件 = true ) then
...
end if;
end loop;
表tbl_1中有记录:a,b,c,d,a,c
表tbl_2中有记录:a,b现在需要从表tbl_1中找出tbl_2中没有的,并将tbl_2中没有的记录insert进tbl_2表中,tbl_2表中的记录不可以重复。即:
将tbl_1中的c,d插入tbl_2中。
(select distinct col col from tbl_1 where not exists (select 1 from tbl_2 where tbl_2.col = tbl_1.col))