oracle pl/sql之oracle預存程序

來源:互聯網
上載者:User

標籤:

      預存程序是一種命名pl/sql程式塊,它可以被賦予參數,儲存在資料庫中,可以被使用者調用。由於預存程序是已編譯好的代碼,所以在調用的時候不必再次進行編譯,從而提高了程式的運行效率。另外使用預存程序可以實現程式的模組化設計

 

預存程序的文法:

create [or replace] procedure procedure_name (parameter [{in| out}]  data_type,

parameter [{in| out}]  data_type....)  

{is|as}

 begin

executable section;

exception

exception handlers;

end;

 

程式示範:

     寫一個預存程序用來向emp表中插入一條資料

create of replace procedure my_procedure3 is
begin
insert into emp(empno,ename) values(9527,‘星爺之唐伯虎‘);
end;

 

控制台中調用預存程序:

 exec 過程名(參數);

 

或者寫一個plsql語句塊

begin

過程名(參數);

end;

 

參數:

oracle 有三種參數模式in out和 in out  in 表示使用者的輸入參數  程式示範: 

create or replace procedure my_procedure(in_no in number,in_name in varchar2) is
begin
insert into emp(empno,ename) values(in_no,in_name);
end;

 

out參數表示使用者的輸出

程式示範:

create or replace procedure my_pro(in_no in number,out_name out varchar2,out_sal out number) is
begin
select ename,sal into out_name,out_sal from emp where empno=in_no;
end;

 

在sqlplus中想得到帶有輸出的過程執行完後的值  方法1:寫匿名塊 


declare
v_name emp.ename%type;
v_sal emp.sal%type;
begin
my_pro(7369,v_name,v_sal);
dbms_output.put_line( v_name);
dbms_output.put_line( v_sal);
end;

 注意:

in out同時具有in和out的特性,在過程中可以讀取和寫入型別參數

 

 

oracle pl/sql之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.