1

It is common to have pages with filters in most asp.net application (usually have 5 or more criterias, EX: filtr by:lastname, firstname, date, etc..).

Mostly dealing with TSQL (SQL Server 2000/2005) . I would deal with criteria(s) in my procedures, for example:

PARAMETERS Param1 VARCHAR(32), Param2 INT; 

SELECT columns FROM table WHERE 
    ([Param1] IS NULL OR column1 = [Param1]) 
    AND 
    ([Param2] IS NULL OR column2 = [Param2])

Can someone show me how optional parameters are dealt PL/SQL, Thanks

1
  • Pretty much the same way. Commented Apr 16, 2017 at 3:22

1 Answer 1

5

For example:

create or replace procedure optPar(a in number, b in number := null, c number := 999) is
begin
    dbms_output.put_line(a || ', ' || b || ', ' || c);
end;

The procedure needs the a parameter:

SQL> exec optPar();
BEGIN optPar(); END;

      *
ERROR at line 1:
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'OPTPAR'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored

You can omit b, c:

SQL> exec optPar(1);
1, , 999

PL/SQL procedure successfully completed.

SQL> exec optPar(1, 2);
1, 2, 999

PL/SQL procedure successfully completed.

SQL> exec optPar(1, 2, 3);
1, 2, 3

PL/SQL procedure successfully completed.

In this case, explicitly passing parameters is even more important then with no optional parameters, to easily understand which value you are giving to each parameter:

SQL> exec optPar( a=> 1, c=> 3);
1, , 3

PL/SQL procedure successfully completed.
Sign up to request clarification or add additional context in comments.

Comments

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.