in out in/out 三種參數的區別

來源:互聯網
上載者:User

第一種:唯讀。參數是唯讀,不能修改,即調用時傳遞進來的是常量,或者變數(但變數不能在預存程序中修改)。通常select及DML類型的預存程序傳遞的是in類型的參數。

第二種:唯寫。忽略調用語句傳遞的任何參數,並在函數(過程)內部給這些參數賦值,因此是唯寫的。(這種情況是在函數或過程內部給參數重新賦值,但重新賦值後的參數是無法被外部調用的(好像遊標類型的參數除外))

CREATE OR REPLACE  PROCEDURE "SCOTT"."SWAP" (firstValue out
    number, secondValue out  number) is
  temp number;
begin
   temp := firstValue;
   firstValue := secondValue;
   secondValue := temp;
end swap;

外部調用:

set serveroutput on;
declare 
        firstVal number;
        secondVal number;
begin
   firstVal := 10;
   secondVal := 20;
   scott.swap(firstVal,secondVal);
   dbms_output.put_line('first is ' || firstVal);
   dbms_output.put_line('second is ' || secondVal);
  end;

無法在外部存取到firstValue與secondValue的值。此時列印出的結果為:

first is
second is
第三種:讀或寫。這可以完全控制參數,讀取傳遞的參數的值。可以再函數(過程)內部修改參數的值,在退出函數(過程)後,這些參數被賦給在函數內部寫入的值,這樣就可以返回多個值。(即入口參數寫入值後,可以傳遞到函數(過程)的外部,供外部調用的時候使用)

ps:函數中的傳回值為如下幾種:

   char;  varchar2; number; integer; date; boolean; table; record

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.