检查plsql中的记录不是空的 [英] Check a record IS NOT NULL in plsql

查看:51
本文介绍了检查plsql中的记录不是空的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a function which would return a record with type my_table%ROWTYPE, and in the caller, I could check if the returned record is null, but PL/SQL complains the if-statement that

PLS-00306:调用IS NOT NULL"时的参数数量或类型错误

PLS-00306: wrong number or types of arguments in call to '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;

谢谢.

推荐答案

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

As far as I know, it's not possible. Checking the PRIMARY KEY or a NOT NULL column should be sufficient though.

您可以检查v_record.row_id IS NULL.

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

Your function would throw a NO_DATA_FOUND exception though, when no record is found.

这篇关于检查plsql中的记录不是空的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆