zoukankan      html  css  js  c++  java
  • plsql的参数IN和OUT

    代码片段一

    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.

    Table 8-1 Parameter Modes

    INOUTIN 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 NOCOPY is specified

    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 NOCOPY is specified

  • 相关阅读:
    剑指 Offer 48. 最长不含重复字符的子字符串
    剑指 Offer 47. 礼物的最大价值
    剑指 Offer 42. 连续子数组的最大和
    剑指 Offer 40. 最小的k个数
    剑指 Offer 39. 数组中出现次数超过一半的数字
    剑指 Offer 34. 二叉树中和为某一值的路径
    剑指 Offer 33. 二叉搜索树的后序遍历序列
    java类与对象(属性,方法)的使用
    java--基本数据类型的转换(强制转换)
    java--基本数据类型的转换(自动转换)
  • 原文地址:https://www.cnblogs.com/zhuqingkfv/p/p20140108.html
Copyright © 2011-2022 走看看