I am looking to do a function with non fixed number of arguments like decode function.
The syntax for the DECODE
function in Oracle/PLSQL is:
DECODE( expression , search , result [, search , result]... [, default] )
I want to do the same [] for example:
SUM(expresion1, expresion2, [expresion]...)
A practical result could be:
SELECT SUM(1,1) FROM dual;
SELECT SUM(1,1,1,1,1,1,1,1,1) FROM dual;
etc
Is that posible in PL/SQL or is this limited to Oracle built-in functions?
Best Answer
DECODE
is an SQL function, not PL/SQL. You can not use it in plain PL/SQL, only as part of SQL statements.There is no nice and easy way for this. There is the method with collections, for example:
Then:
There are built-in, non-documented simple list types, so you do not need to define your own types at all circumstances, but relying on non-documented features is generally bad practice, as they may change in newer versions without warning.
If there is a reasonable limit for the number of arguments:
Obviously, these are neither tidy nor effective.