日期:2014-05-17 浏览次数:21270 次
CREATE OR REPLACE PROCEDURE TEST_1 (P_IN_TBNAME IN VARCHAR2) IS REF_CUR SYS_REFCURSOR ; V_SQL VARCHAR2(2000) ; V_ROWID ROWID ; BEGIN V_SQL := 'SELECT ROWID FROM '|| P_IN_TBNAME ; OPEN REF_CUR FOR V_SQL ; LOOP FETCH REF_CUR INTO V_ROWID; EXIT WHEN REF_CUR%NOTFOUND; DBMS_OUTPUT.PUT_LINE(V_ROWID) ; END LOOP ; --business process CLOSE REF_CUR ; EXCEPTION WHEN OTHERS THEN --exception handle RAISE ; END ; / SQL> CREATE TABLE TST1 (X INT) ; Table created SQL> INSERT INTO TST1 VALUES (1) ; 1 row inserted SQL> SET SERVEROUTPUT ON ; SQL> EXEC TEST_1('TST1') ; AAATeuAAHAAAAuHAAA PL/SQL procedure successfully completed
------解决方案--------------------
根据LZ的意思大概改成这样子。。
create or replace procedure case_to_province(table_name in varchar2, id_name in varchar2) declare cur is ref cursor ; v_id table_name.id%type; test_cursor cur; begin open test_cursor for select id from table_name where name=id_name; loop fetch test_coursor in v_id; exit when test_cursor%not found; end loop; end; /