代码片段一
1 create or replace procedure scott.pro_para_inout(p_dname in out scott.dept.dname%TYPE, 2 p_loc out scott.dept.loc%TYPE) is 3 begin 4 dbms_output.put_line(p_dname || ',ING'); 5 dbms_output.put_line(p_loc || ',ING' ); 6 end pro_para_inout;
调用
DECLARE v_dept scott.dept%ROWTYPE; BEGIN v_dept.dname :='bumon1'; v_dept.loc :='SH'; -- Call the procedure scott.pro_para_inout(v_dept.dname, v_dept.loc); dbms_output.put_line(v_dept.dname || ',after'); dbms_output.put_line(v_dept.loc || ',after'); end;
结果
bumon1,ING
,ING
bumon1,after
,after
当参数类型是OUT的情况下,原来record(v_dept)中的值也没有了。如果是IN OUT的情况下,原来record的值还保持了原来的样子。
当然根据实际情况使用的时候设置就可以了,但是如果是预想某种情况下就重新设定值,不满足条件就什么也不做,原值不变的话,写成OUT就错了。
关于oracle的参数的值传递,还是引用传递,官方是这么解释的。
Summary of Subprogram Parameter Modes
Table 8-1 summarizes the characteristics of parameter modes.
IN | OUT | IN OUT |
---|---|---|
The default |
Must be specified |
Must be specified |
Passes a value to the subprogram |
Returns a value to the caller |
Passes an initial value to the subprogram and returns an updated value to the caller |
Formal parameter acts like a constant |
Formal parameter acts like an uninitialized variable |
Formal parameter acts like an initialized variable |
Formal parameter cannot be assigned a value |
Formal parameter must be assigned a value |
Formal parameter should be assigned a value |
Actual parameter can be a constant, initialized variable, literal, or expression |
Actual parameter must be a variable |
Actual parameter must be a variable |
Actual parameter is passed by reference (the caller passes the subprogram a pointer to the value) |
Actual parameter is passed by value (the subprogram passes the caller a copy of the value) unless |
Actual parameter is passed by value (the caller passes the subprogram a copy of the value and the subprogram passes the caller a copy of the value) unless |