Ram*_*Ram 1 oracle plsql optional-parameters
在大多数 ASP.NET 应用程序中,带有过滤器的页面很常见(通常有 5 个或更多条件,例如:filter by:lastname、firstname、date 等)。
主要处理 TSQL (SQL Server 2000/2005)。我会在程序中处理标准,例如:
PARAMETERS Param1 VARCHAR(32), Param2 INT;
SELECT columns FROM table WHERE
([Param1] IS NULL OR column1 = [Param1])
AND
([Param2] IS NULL OR column2 = [Param2])
Run Code Online (Sandbox Code Playgroud)
有人可以告诉我如何处理可选参数 PL/SQL,谢谢
例如:
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;
Run Code Online (Sandbox Code Playgroud)
程序需要a参数:
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
Run Code Online (Sandbox Code Playgroud)
您可以省略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.
Run Code Online (Sandbox Code Playgroud)
在这种情况下,显式传递参数比没有可选参数更重要,以便轻松理解为每个参数赋予的值:
SQL> exec optPar( a=> 1, c=> 3);
1, , 3
PL/SQL procedure successfully completed.
Run Code Online (Sandbox Code Playgroud)