代碼片段一
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 |
