我有一个开发的应用程序,其中包含大量行,而我正在使用ref游标,但我不需要游标。如何做到这一点。
here is below code i was using ref cursor please help me out how can avoid it.any idea
create or replace
PROCEDURE remove_emp
(
employee_id in NUMBER,
o_data out sys_refcursor
)
AS
v_account_status help.topic%type;
v_username help.seq%type;
v_lock_date help.info%type;
BEGIN
open o_data for
select topic,seq, info
into v_account_status,v_username,v_lock_date
from help;-- where seq=employee_id ;
DBMS_OUTPUT.put_line ('topic:'||v_account_status);
DBMS_OUTPUT.put_line ('seq:'||v_username);
DBMS_OUTPUT.put_line ('info:'||v_lock_date);
END remove_emp;
答案 0 :(得分:1)
只需删除光标,然后使用SELECT ... INTO ...
:
Oracle设置:
CREATE TABLE help ( topic, seq, info ) AS
SELECT 'a', 1, 'aa' FROM DUAL UNION ALL
SELECT 'b', 2, 'bb' FROM DUAL UNION ALL
SELECT 'c', 3, 'cc' FROM DUAL;
过程:
create PROCEDURE remove_emp
(
employee_id in help.seq%type
)
AS
v_account_status help.topic%type;
v_username help.seq%type;
v_lock_date help.info%type;
BEGIN
select topic,seq, info
into v_account_status,v_username,v_lock_date
from help where seq=employee_id;
DBMS_OUTPUT.put_line ('topic:'||v_account_status);
DBMS_OUTPUT.put_line ('seq:'||v_username);
DBMS_OUTPUT.put_line ('info:'||v_lock_date);
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.put_line ('seq:Not Found!');
END remove_emp;
/
调用过程:
BEGIN
remove_emp(1);
END;
/
输出:
topic:a seq:1 info:aa
db <>提琴here