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

  • 相关阅读:
    【linux】驱动-5-驱动框架分层分离&实战
    【linux】驱动-4-LED芯片手册分析
    【MCU】国民N32固件库移植
    【MCU】移植AT32库&FreeRTOS教程
    P3768 简单的数学题
    P4301 [CQOI2013] 新Nim游戏
    P4767 [IOI2000]邮局
    P3211 [HNOI2011]XOR和路径
    FWT 笔记
    P3175 [HAOI2015]按位或(max-min 容斥)
  • 原文地址:https://www.cnblogs.com/zhuqingkfv/p/p20140108.html
Copyright © 2011-2022 走看看