Oracle預存程序代碼執行個體一則

來源:互聯網
上載者:User

1、用來插入大量測試資料的預存程序
CREATE OR REPLACE PROCEDURE INSERTAMOUNTTEST
(
ST_NUM        IN     NUMBER,
ED_NUM        IN     NUMBER
)
IS
BEGIN
declare
       i   number;
begin
FOR i IN ST_NUM..ED_NUM LOOP
INSERT INTO tb values(i,i,'3','3','3',100,'0');
END LOOP;
end;
END;

運行:
sql>execute INSERTAMOUNTTEST(1,45000)   -- 一次插入45000條測試資料

2、從預存程序中傳回值
create or replace procedure spaddflowdate
(
varAppTypeId               in varchar2,
varFlowId                  in varchar2,
DateLength                 in number,
ReturnValue                out number    --傳回值
)
is
begin
insert into td values(varAppTypeId,varFlowId,DateLength)
returning 1 into ReturnValue;   --傳回值
commit;
exception
when others then
rollback;
end;

預存程序的執行
sql>variable testvalue  number;
sql>execute spaddflowdate('v','v',2,:testvalue);
sql>print
就可以看到執行結果

3、用包實現預存程序返回遊標:
create  or  replace  package  test_p 
as 
 
type  outList  is  ref  cursor; 
 
PROCEDURE  getinfor(taxpayerList  out  outList); 
 
end  test_p; 


create  or  replace  package  body  test_p  as  PROCEDURE  getinfor(taxpayerList out  outList)  is  begin 
      OPEN  taxpayerList    FOR  select  *  from
                        td where tag='0'; 
 
end  getinfor; 
 
end  test_p; 

 
 
 
運行:
 
set  serverout  on;    --將輸出工具開啟
 
variable  x  refcursor; 
 
execute test_p.getinfor(:x);

exec  test_p.getinfor(:x);
 
print  x; 


drop package test_p;

聯繫我們

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