检查plsql中的记录IS NOT NULL

Sap*_*nce 21 plsql notnull

我有一个函数,它将返回一个类型的记录my_table%ROWTYPE,并在调用者,我可以检查返回的记录是否为空,但PL/SQL抱怨if语句

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;
Run Code Online (Sandbox Code Playgroud)

谢谢.

Pet*_*ang 31

据我所知,这是不可能的.但是检查PRIMARY KEYNOT NULL列应该足够了.


你可以检查一下v_record.row_id IS NULL.

NO_DATA_FOUND但是,当没有找到记录时,您的函数会抛出异常.

  • 据我所知,这是不可能的.检查`PRIMARY KEY`或`NOT NULL`列应该足够了. (3认同)