oracle對象之儲存函數

來源:互聯網
上載者:User

標籤:例子   預存程序   tput   查詢   對象   返回   str   number   output   

儲存函數

create or replace function 函數名(Name in type, Name out type, ...) return 資料類型 is

  結果變數 資料類型;

begin

  return(結果變數);

end[ 函數名 ];

預存程序和儲存函數的區別

一般來講,過程和函數的區別在於函數可以有一個傳回值;而過程沒有傳回值。

但過程和函數都可以通過out指定一個或多個輸出參數。我們可以利用out參數,在過程和函數中實現返回多個值。一般來講,有一個傳回值的時候用儲存函數,多個傳回值用預存程序。 範例:使用儲存函數來查詢指定員工的年薪 
 1 create or replace function empincome(eno in emp.empno%type) return number is 2   3   psal  emp.sal%type; 4   5   pcomm emp.comm%type; 6   7 begin 8   9   select t.sal into psal from emp t where t.empno = eno;10  11   return psal * 12 + nvl(pcomm, 0);12  13 end;

 

 使用預存程序來替換上面的例子
 1   2 create or replace procedure empincomep(eno in emp.empno%type, income out number) is 3   4   psal emp.sal%type; 5   6   pcomm emp.comm%type; 7   8 begin 9  10   select t.sal, t.comm into psal, pcomm from emp t where t.empno = eno;11  12   income := psal*12+nvl(pcomm,0);13  14 end empincomep;

 

調用:
 1   2 declare 3   4   income number; 5   6 begin 7   8   empincomep(7369, income); 9  10   dbms_output.put_line(income);11  12 end;

 

oracle對象之儲存函數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.