oracle 我可以执行带有默认空参数的过程吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18406967/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can I execute a procedure with default null parameters?
提问by user2405778
I recently created a procedure that is defined like this:
我最近创建了一个定义如下的过程:
create or replace
PACKAGE
pkg_dml_legal_transactions
AS
PROCEDURE spm_update_court_cost(
p_court_state IN legal_court_cost.state%TYPE,
p_tran_code IN legal_court_cost.transaction_code%TYPE,
p_legal_court IN legal_court_cost.court%TYPE default null,
p_end_date IN legal_court_cost.end_date%TYPE,
p_cost_min IN legal_court_cost.cost_range_min%TYPE,
p_cost_max IN legal_court_cost.cost_range_max%TYPE,
p_bal_min IN legal_court_cost.bal_range_min%TYPE DEFAULT NULL,
p_bal_max IN legal_court_cost.bal_range_max%TYPE DEFAULT NULL);
end pkg_dml_legal_transactions;
When I attempt to execute
the procedure, I get an error stating that:
当我尝试执行execute
该程序时,我收到一条错误消息,指出:
PLS-00306: wrong number or types of arguments in call to 'SPM_UPDATE_COURT_COST'
Here is what my execute statement looks like:
这是我的执行语句的样子:
execute pkg_dml_legal_transactions.spm_update_court_cost('NJ',1,sysdate,1000,40000);
Now I understand what the error means, but I figured if the parameters are defaulted to null then I could just skip them over, but apparently not. Is there a way around this?
现在我明白了错误的含义,但我想如果参数默认为 null 那么我可以跳过它们,但显然不是。有没有解决的办法?
回答by Justin Cave
In PL/SQL, you can call a procedure using either named parameter notation or positional notation. If you want to skip some parameters, you'll need to use named parameter notation
在 PL/SQL 中,您可以使用命名参数表示法或位置表示法调用过程。如果要跳过某些参数,则需要使用命名参数表示法
execute pkg_dml_legal_transactions.spm_update_court_cost( p_court_state => 'NJ',
p_tran_code => 1,
p_end_date => sysdate,
p_cost_min => 1000,
p_cost_max => 40000 );
Generally, when you're designing a procedure, you would put all the optional parameters at the end so that the caller could also use positional notation.
通常,在设计过程时,会将所有可选参数放在最后,以便调用者也可以使用位置表示法。
回答by foobarbaz
You can use mixed approach, positional notation until first omitted parameter, named notation for the rest.
您可以使用混合方法,位置符号直到第一个省略参数,其余的命名符号。
declare
procedure do_something(p_foo IN NUMBER
,p_bar IN VARCHAR2 DEFAULT NULL
,p_baz IN VARCHAR2) IS
begin
null;
end;
begin
do_something(12, p_baz => 'abc');
end;
But I would choose what Justin proposed.
但我会选择贾斯汀提议的。