oracle实参与形参有两种对应方式
1.一种是位置方式,和面向对象语言参数传递类似;
2.另外一种是=> 作为形参对应,因为位置对应方法有缺限,比如一个函数有3个参数,但第2个是可以不传(有默认值),这里就没办法位置对应方法,oralce内部一般用此种方法作参数传递。
CREATE OR REPLACE PROCEDURE HelloWorld( p_user_name VARCHAR2, p_val1 VARCHAR2 DEFAULT ‘ Good Moning,‘, p_val2 VARCHAR2 DEFAULT ‘ Nice to Meet you‘ ) AS BEGIN dbms_output.put_line(‘Hello ‘ || p_user_name || p_val1 || p_val2 || ‘!‘ ); END HelloWorld; /
--使用第一种位置方式 BEGIN HelloWorld(‘Edward‘); HelloWorld(‘Edward‘, ‘ Good Night,‘); HelloWorld(‘Edward‘, ‘ Good Night,‘, ‘Bye‘); END; / --结果 Hello Edward Good Moning, Nice to Meet you! Hello Edward Good Night, Nice to Meet you! Hello Edward Good Night,Bye!
--使用=> 作为形参对应 BEGIN HelloWorld(‘Edward‘); HelloWorld(‘Edward‘, p_val1 => ‘ Good Night,‘); HelloWorld(‘Edward‘, p_val1 => ‘ Good Night,‘, p_val2 => ‘Bye‘); HelloWorld(‘Edward‘, p_val2 => ‘ HeiHei ‘); --使用=>符号,跳过中间的默认值 END; / --结果 Hello Edward Good Moning, Nice to Meet you! Hello Edward Good Night, Nice to Meet you! Hello Edward Good Night,Bye! Hello Edward Good Moning, HeiHei !