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;