oracle預存程序文法

來源:互聯網
上載者:User

預存程序 包含三部分: 聲明,執行部分,異常。    
可以有無參數程式和帶參數預存程序。    
無參程式文法    
1 create or replace procedure NoParPro   
2 as   ;   
3 begin   
4  ;   
5 exception   
6      ;   
7 end;   
8    
  
   帶參預存程序執行個體    
 1 create or replace procedure queryempname(sfindno emp.empno%type) as   
 2        sName emp.ename%type;   
 3        sjob emp.job%type;   
 4 begin   
 5        ....   
 7 exception   
          ....   
14 end;   
15    
  
   帶參數預存程序含賦值方式    
 1 create or replace procedure runbyparmeters  (isal in emp.sal%type,    
                            sname out varchar,sjob in out varchar)   
 2  as icount number;   
 3  begin   
 4       select count(*) into icount from emp where sal>isal and job=sjob;   
 5       if icount=1 then   
 6         ....   
 9       else  
10         ....   
12       end if;   
13  exception   
14       when too_many_rows then   
15       DBMS_OUTPUT.PUT_LINE('傳回值多於1行');   
16       when others then   
17       DBMS_OUTPUT.PUT_LINE('在RUNBYPARMETERS過程中出錯。');   
18  end;   
19    
  
  程序呼叫   
  方式一   
 1 declare   
 2        realsal emp.sal%type;   
 3        realname varchar(40);   
 4        realjob varchar(40);   
 5  begin   
 6        realsal:=1100;   
 7        realname:='';   
 8        realjob:='CLERK';   
 9        runbyparmeters(realsal,realname,realjob);     --必須按順序   
10        DBMS_OUTPUT.PUT_LINE(REALNAME||'   '||REALJOB);   
11  END;   
12    
  
  方式二   
 1 declare   
 2       realsal emp.sal%type;   
 3       realname varchar(40);   
 4       realjob varchar(40);   
 5 begin   
 6       realsal:=1100;   
 7       realname:='';   
 8       realjob:='CLERK';   
 9       runbyparmeters(sname=>realname,isal=>realsal,sjob=>realjob);  --指定值對應變數順序可變   
10       DBMS_OUTPUT.PUT_LINE(REALNAME||'   '||REALJOB);   
11 END;   
12 

聯繫我們

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