Reputation: 7519
I have an oracle Procedure and I want to set the default parameter to the result of a select statement such as below.
procedure foo( startID number : = max(x.id) from xtable x )
but the code above is illegal syntax.
Upvotes: 2
Views: 13532
Reputation: 67752
You can use an otherwise unvalid value for this meaning, for example NULL:
PROCEDURE foo (p_id NUMBER DEFAULT NULL) IS
l_startID NUMBER := p_id;
BEGIN
IF p_id IS NULL THEN
SELECT max(id) INTO l_startID FROM xtable;
END IF;
...
END;
If your function/procedure is in a package, you could also overload it:
PROCEDURE foo (p_id NUMBER)
[...]
PROCEDURE foo IS
l_startID NUMBER;
BEGIN
SELECT max(id) INTO l_startID FROM xtable;
foo(l_startID);
END;
Upvotes: 8