Re: [SQL ] 關於procedure中select結果有可能會空ꨠ…
※ 引述《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
討論串 (同標題文章)
完整討論串 (本文為第 5 之 6 篇):