如果表类型参数为null,则获取所有记录

时间:2018-07-11 15:34:28

标签: sql oracle plsql

在Oracle中,如果表值参数为null,则我想获取column的所有值,否则仅获取匹配的记录。

create or replace PROCEDURE pr_Employees (
    lastnames IN LastName,
    rowCursor OUT SYS_REFCURSOR) IS
BEGIN
Select * from emp where lastname in (
    SELECT COLUMN_VALUE FROM TABLE(lastnames)
)

1 个答案:

答案 0 :(得分:1)

尝试一下:

create or replace procedure pr_employees
    ( lastnames in lastname
    , rowcursor out sys_refcursor )
is
begin
    open rowcursor for
        select * from emp
        where  lastname in
               ( select column_value from table(lastnames) )
        or     lastnames is empty;
end pr_employees;