我想获取游标的一行记录,但是这样写是不对的,(v_row v_tab%rowtype;有错误)该怎样改正啊,多谢了!
create or replace procedure case_update_info( v_tab varchar2) as
type cur_type is ref cursor;
my_cur cur_type;
v_row v_tab%rowtype;
dyna_sql varchar2(1000);
begin
dyna_sql := 'select id from '||v_tab||' where rownum=1';
open my_cur for dyna_sql;
fetch my_cur into v_row;
while my_cur%found LOOP
……
end loop;
end case_update_info;
------解决方案--------------------
把整个逻辑用动态执行,可参考如下代码:
- SQL code
CREATE OR REPLACE PROCEDURE p01(tablename IN VARCHAR2) AS v_sql VARCHAR2(500):='DECLARE type c_curref is ref cursor;r_curref c_curref;rec_c '||tablename||'%ROWTYPE;BEGIN OPEN r_curref FOR ''select * from '||tablename|| ' where rownum=1''; LOOP FETCH r_curref INTO rec_c; EXIT WHEN r_curref%NOTFOUND; Dbms_Output.put_line(''the SEQUENCE_NAME is :''||rec_c.SEQUENCE_NAME); END LOOP; CLOSE r_curref;END;';BEGIN execute immediate v_sql;END p01;EXEC p01('user_sequences');输出:the SEQUENCE_NAME is :S_DHBA2_SQNO