没有问题呀!!!!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>
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>
解决方案 »
- 如何将毫秒形式的数据库日期字段转换成“YYYY-MM-DD”的形式?
- sql语句优化
- 如何PL-SQL中SQL WINDOW 执行字符串型SQL
- 是否要用数据库存取硬盘数据?!!
- 在Pro*C中嵌入PL/SQL编译不成功的问题
- 百分求教一个简单的触发器(在线),求两列的合计值赋给第三列
- 不小心在Enterprise Manager Console删除了数据库
- 关于ORACLE的重装!
- 谁能告诉我有介绍关于stored program unit “type”概念的地方!帮我在这儿解释一下也行!
- 怎样判断存在记录!这种PL/SQL语句怎么写!在线等待!
- c366的机器装oracle9效果怎样?内存198
- 请教怎样进行三表的左联接或由联接?
错误依然存在,我用的是8.0.5版,有问题吗?
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 /警告:已创建的程序包主体出现编译错误。
我测试成功是在8.1.7上面。
我在8.0.6上试了一下,和你抱的错误一样!!!
SQL> create or replace package comm_types
2 AS
3 TYPE COMM_CURSOR IS REF CURSOR;
4 END comm_types;
5 /程序包已创建。