我有一個函數會返回一個類型爲my_table%ROWTYPE
的記錄,並且在調用者中,我可以檢查返回的記錄是否爲空,但是PL/SQL抱怨if語句查看記錄IS NOT NULL在plsql中
PLS-00306:錯號碼或類型的呼叫參數 'IS NOT NULL'
這裏是我的代碼:
v_record my_table%ROWTYPE;
v_row_id my_table.row_id%TYPE := 123456;
begin
v_record := myfunction(v_row_id)
if (v_record is not null) then
-- do something
end if;
end;
function myfunction(p_row_id in my_table.row_id%TYPE) return my_table%ROWTYPE is
v_record_out my_table%ROWTYPE := null;
begin
select * into v_record_out from my_table
where row_id = p_row_id;
return v_record_out;
end myfunction;
感謝。
感謝您的回答。這是檢查記錄是否爲空的唯一方法嗎?我很奇怪我們可以將null分配給記錄,但不能檢查記錄是否爲空。 – Sapience
據我所知,這是不可能的。雖然檢查'PRIMARY KEY'或'NOT NULL'列應該是足夠的。 –
很好的解決方法!我使用'NULL'分配記錄,這是檢查的方式! +1 – gavenkoa