大概这样 create or replace procedure p_XX(tabName in varchar2) is type t_cursor is ref cursor; v_cursor t_cursor; v_SQLStatement varchar2(300);
begin v_SQLStatement = 'select xx from '||tabName ; open v_cursor for v_SQLStatement; loop fetch v_cursor into XXX; exit when v_cursor%notfound; --做你的操作 end loop; close v_cursor; end;
霸道小蛮女
2024-04-20 01:13:06
在Oracle 11G中,应修改为: CREATE OR REPLACE PROCEDURE P_XX(TABNAME IN VARCHAR2) IS TYPE T_CURSOR IS REF CURSOR; V_CURSOR T_CURSOR; V_SQLSTATEMENT VARCHAR2(256); VALUE VARCHAR2(256); BEGIN V_SQLSTATEMENT := 'SELECT DUMMY FROM '||TABNAME ; OPEN V_CURSOR FOR V_SQLSTATEMENT; LOOP FETCH V_CURSOR INTO VALUE; EXIT WHEN V_CURSOR%NOTFOUND; --做你的操作 DBMS_OUTPUT.PUT_LINE('MY FIRST PROCEDURE, CREATE AT 2018-11-25 19:24.'); DBMS_OUTPUT.PUT_LINE(VALUE); END LOOP; CLOSE V_CURSOR; END;