oracle儲存過程呼叫游標例子

2021-07-26 12:34:39 字數 965 閱讀 3527

1:首先你需要建立乙個包,並定義你返回的游標的型別、儲存過程 

create or replace package test_pkg is 

--定義游標 

type t_cur is ref cursor; 

--儲存過程宣告 

procedure test_proc (p_cur in out t_cur); 

end test_pkg; 

2:然後你再建立包體 

create or replace package body test_pkg is 

--在包體中定價過程 

procedure test_proc (p_cur in out t_cur) 

as begin 

open p_cur for select * from test where rownum=1; 

end test_proc; 

end test_pkg ; 

3.呼叫返回游標的過程 

create or replace procedure test1_proc as 

p_cur1 test_pkg.t_cur; 

p_id varchar2(100); 

p_name varchar2(100); 

begin 

test_pkg.test_proc(p_cur1); 

loop  

fetch p_cur1 into p_id,p_name; 

exit when p_cur1%notfound; 

dbms_output.put_line(p_id); 

dbms_output.put_line(p_name); 

end loop; 

end test1_proc; 

4.執行呼叫的過程 

set serveroutput on 

exec test1_proc; 

Oracle使用游標迴圈呼叫儲存過程

宣告游標 cursor cursor name is select statement for 迴圈游標 1 定義游標 2 定義游標變數 3 使用for迴圈來使用這個游標 declare 型別定義 cursor c job is select a.workorderid from idc.pf or...

mybatis中呼叫游標,儲存過程,函式

在ibatis和mybatis對儲存過程和函式函式的呼叫的配置xml是不一樣的,以下是針對mybatis 3.2的環境進行操作的。call pkg rrt selfstatics.fn getselfstatdata 說明 1 result對應的是oracle自定義函式返回的游標 2 對映物件res...

Mysql 儲存過程使用游標

完整例子 create procedure test begin 定義引數 declare id int 定義游標 declare no more products int default 0 declare result test cursor for select num1 from numte...