郁闷的大象

 

sql 循环

 
#4楼 得分:0回复于:2006-07-06 14:42:11
可以在循环里增加一个条件判断吧,如果满足条件则不处理,继续循环
ex:
for   i   in   1   ..   num   loop
if   (符合某个条件   =   true   )   then  
...
end   if;
end   loop;
 
 
 
#7楼 得分:0回复于:2006-07-06 15:07:49
呵呵,num   是你循环的次数,只是举一个循环的例子
可以不一定是for   循环,也可以是   while   循环,或者是简单的   Loop循环
 
 
#8楼 得分:0回复于:2006-07-06 15:13:23
就用loop循环吧,给个例子看看。
需要实现关键点:如何跳过不符合条件的,操作符合条件的
 
 
 
#9楼 得分:0回复于:2006-07-06 15:13:45
可以在游标里面过滤掉不符合条件的记录,或者在循环里加上一个判断阿
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;
 
 
#10楼 得分:0回复于:2006-07-06 15:21:03
可能是我没有说的详细,举个简单的例子:
表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中。
 
 
 
1楼 得分:30回复于:2006-07-06 15:40:56
insert   into   tbl_2  
(select   distinct   col   col   from   tbl_1   where   not   exists   (select   1   from   tbl_2   where   tbl_2.col   =   tbl_1.col))
 
 
 
#12楼 得分:0回复于:2006-07-06 16:01:08
嗯,这个sql也可以解决,给分

posted on 2011-12-03 13:06  郁闷的大象  阅读(1234)  评论(0编辑  收藏  举报

导航