0

In Oracle, I want to get all values of column if the table valued parameter is null otherwise only the matched records.

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 Answer 1

1

Try this:

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;
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your help. I tried above one, If I passed lastnames is null it is returning 0 records.
How is last name defined? I made mine a table of varchar2(60). How are you setting the parameter value when you call it? I've handled the case where you pass an empty collection, not a collection of null values.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.