create or replace PROCEDURE tr_executesql (sqlstring IN VARCHAR2) AS
  cid NUMBER;
  numrows integer;
BEGIN
  DBMS_OUTPUT.PUT_LINE(sqlstring);
  /* Open new cursor and return cursor ID. */
  cid := DBMS_SQL.OPEN_CURSOR;
  /* Parse and immediately execute dynamic SQL statement. */
  DBMS_SQL.PARSE(cid, sqlstring, DBMS_SQL.V7);
  numrows := DBMS_SQL.EXECUTE(cid);
  /* Close cursor. */  
  DBMS_SQL.CLOSE_CURSOR(cid);
EXCEPTION
  /* If an exception is raised, close cursor before exiting. */
  WHEN OTHERS THEN
      DBMS_SQL.CLOSE_CURSOR(cid);
      RAISE;  -- reraise the exception
END tr_executesql;用tr_executesql执行动态的select

解决方案 »

  1.   

    create or replace package test
    is 
    type mycur is ref cursor ;
    procedure get(p out mycur) ;
    end test ;create or replace package body test
    as 
    procedure get(p out mycur)
    is
    begin
    open p for select * from emp ;
    end get ;
    end test ;
    给你个看看改一下
      

  2.   

    他的SQL语句是从外面动态传进来的,在楼上的基础上修改一下:
    create or replace package test
    is 
    type mycur is ref cursor ;
    procedure get(sqlstring int varhcar2,p out mycur) ;
    end test ;create or replace package body test
    as 
    procedure get(sqlstring int varhcar2,p out mycur)
    is
    begin
    open p for sqlstring;
    end get ;
    end test ;