作者alexcwtzeng (狂泻不止)
看板Database
标题Re: [SQL ] 关於procedure中select结果有可能会空ꨠ…
时间Wed Aug 29 00:38:24 2007
※ 引述《diamondking (天剑流星)》之铭言:
: 常常遇到一个情形,
: 当想执行一小段的sql,但select出来的结果为空值,就会出错…
: 例如(以oracle为例):
: declare
: v_c int :=0;
: begin
: select num into v_c from table where.....;
: ....
: ....
: end;
恕删:
个人比较会用安全的方法 (Oracle)
declare
cursor c1 is
select num from table where ....;
c1rec c1%rowtype;
begin
for c1rec in c1
loop
exist when c1%notfound;
.........
end loop;
end;
很长也很多余的 cursor 宣告,也很多余的 loop
但个人为了避免以下问题最後只好用这一个方案
1. 不需要 hendel exception
2. 程式逻辑可以很好了解,不会出现断层
个人浅见,欢迎大家讨论
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 59.112.85.59