1. 程式人生 > >在儲存過程中,關於出現null的問題

在儲存過程中,關於出現null的問題

假設有一個表A,定義如下:

create table A(

id varchar2(50) primary key not null,

vcount number(8) not null,

bid varchar2(50) not null -- 外來鍵

);如果在儲存過程中,使用如下語句:

select sum(vcount) into fcount from A where bid='xxxxxx';如果A表中不存在bid="xxxxxx"的記錄,則fcount=null(即使fcount定義時設定了預設值,如:fcount number(8):=0依然無效,fcount還是會變成null),這樣以後使用fcount時就可能有問題,所以在這裡最好先判斷一下:

if fcount is null then

fcount:=0;

end if;這樣就一切ok了。