没有问题呀!!!!SQL> CREATE TABLE student
  2   (
  3    id                         NUMBER,
  4    name                       VARCHAR2(30),
  5    sex                        VARCHAR2(10),
  6    address                    VARCHAR2(100),
  7    postcode                   VARCHAR2(10),
  8    birthday                   DATE,
  9    photo                      LONG RAW
 10   )
 11  /Table created.Elapsed: 00:00:01.32
SQL> commit;Commit complete.Elapsed: 00:00:00.10
SQL> CREATE OR REPLACE
  2  package pkg_test as
  3  /* 定义ref cursor类型
  4     不加return类型,为弱类型,允许动态sql查询,
  5     否则为强类型,无法使用动态sql查询;
  6  */
  7    type myrctype is ref cursor;
  8
  9  --函数申明
 10    function get(intID number) return myrctype;
 11  end pkg_test;
 12  /Package created.Elapsed: 00:00:00.30
SQL> CREATE OR REPLACE
  2  package body pkg_test as
  3  --函数体
  4     function get(intID number) return myrctype is
  5       rc myrctype;  --定义ref cursor变量
  6       sqlstr varchar2(500);
  7     begin
  8       if intID=0 then
  9          --静态测试,直接用select语句直接返回结果
 10          open rc for select id,name,sex,address,postcode,birthday from stude
nt;
 11       else
 12          --动态sql赋值,用:w_id来申明该变量从外部获得
 13          sqlstr := 'select id,name,sex,address,postcode,birthday from studen
t where id=:w_id';
 14          --动态测试,用sqlstr字符串返回结果,用using关键词传递参数
 15          open rc for sqlstr using intid;
 16       end if;
 17
 18       return rc;
 19     end get;
 20
 21  end pkg_test;
 22  /Package body created.Elapsed: 00:00:00.90
SQL>

解决方案 »

  1.   

    pls-00103:出现符号“sqlstr”在需要下列之一时:select
    错误依然存在,我用的是8.0.5版,有问题吗?
      

  2.   

    SQL> CREATE OR REPLACE
      2  package body pkg_test as
      3  --函数体
      4     function get(intID number) return myrctype is
      5       rc myrctype;  --定义ref cursor变量
      6       sqlstr varchar2(500);
      7     begin
      8       if intID=0 then
      9          --静态测试,直接用select语句直接返回结果
     10          open rc for select id,name,sex,address,postcode,birthday from student;
     11       else
     12          --动态sql赋值,用:w_id来申明该变量从外部获得
     13          sqlstr := 'select id,name,sex,address,postcode,birthday from student where id=:w_id';
     14          --动态测试,用sqlstr字符串返回结果,用using关键词传递参数
     15          open rc for sqlstr using intid;
     16       end if;
     17  
     18       return rc;
     19     end get;
     20  
     21  end pkg_test;
     22  /警告:已创建的程序包主体出现编译错误。
      

  3.   

    应该是8.0.5的问题,对ref cursor不支持.
    我测试成功是在8.1.7上面。
    我在8.0.6上试了一下,和你抱的错误一样!!!
      

  4.   

    但是包没有抱错亚:
    SQL> create or replace package comm_types 
      2  AS
      3  TYPE COMM_CURSOR IS REF CURSOR;
      4  END comm_types;
      5  /程序包已创建。