自定义类型: create or replace type arry_number as table of number(15);以下是函数片段:l_data arry_number := arry_number();update t_config
set configvalue =1
where configtype = 2
returnning configid
bulk collect
into l_data --这里已经取到值了。。open p_cursor for
select t.configid form t_config t where t.configid in (
select column_value
from TABLE ( cast ( l_data as arry_number) )
这一段代码不能获取到值,不知道是cast有问题,还是select语句有问题
);
说明:
语法没有问题。编译也通过了。现在的问题是最后那一段获取不到值,不知道是cast转换有问题,还是哪里有问题,有没有牛人帮忙解决以下问题。。很急,在线等。
set configvalue =1
where configtype = 2
returnning configid
bulk collect
into l_data --这里已经取到值了。。open p_cursor for
select t.configid form t_config t where t.configid in (
select column_value
from TABLE ( cast ( l_data as arry_number) )
这一段代码不能获取到值,不知道是cast有问题,还是select语句有问题
);
说明:
语法没有问题。编译也通过了。现在的问题是最后那一段获取不到值,不知道是cast转换有问题,还是哪里有问题,有没有牛人帮忙解决以下问题。。很急,在线等。
以下是函数片段:l_data arry_number := arry_number();update t_config
--我写的你们块,把里面改成你的函数体就可以了,上面你写得有较多的错别的关键字
QL> desc t_config
名称 是否为空? 类型
----------------------------------------- -------- --------------------------
CONFIGID NUMBER(15)
CONFIGVALUE NUMBER
CONFIGTYPE NUMBERQL> select * from t_config
2 / CONFIGID CONFIGVALUE CONFIGTYPE
--------- ----------- ----------
1 1 1
2 2 1
3 3 1
4 4 1
5 5 1
6 6 1
7 7 1
8 8 1
9 9 1
10 10 1
11 1 2 CONFIGID CONFIGVALUE CONFIGTYPE
--------- ----------- ----------
12 1 2
13 1 2
14 1 2
15 1 2
15 15 3
16 16 3
17 17 3
18 18 3已选择19行SQL> declare
2 l_data arry_number := arry_number();
3 type p_cursor_type is ref cursor;
4 p_cursor p_cursor_type;
5 v_configid t_config.configid%type;
6 begin
7 update t_config set configvalue =1 where configtype = 2
8 returning configid bulk collect into l_data;
9 open p_cursor for select t.configid from t_config t where t.configid in (
10 select column_value from TABLE(l_data));
11 fetch p_cursor into v_configid;
12 while p_cursor%found loop
13 dbms_output.put_line(v_configid);
14 fetch p_cursor into v_configid;
15 end loop;
16 close p_cursor;
17 end;
18 /
11
12
13
14
15
15PL/SQL 过程已成功完成。
open p_cursor for
select t.configid,t.configname,t.congfigtype form t_config t where t.configid in (
select column_value
from TABLE ( cast ( l_data as arry_number) )
最后把游标p_cursor 返回出去。
弱弱的问一下:
open p_cursor for select t.configid from t_config t where t.configid in (
select column_value from TABLE(l_data));
这里不转换可以吗?
open p_cursor for select t.configid from t_config t where t.configid in (
select column_value from TABLE(l_data)); 如果不做转换,会出现异常。是什么原因呢?
create or replace type array_number as table number(15);--定义一个游标
create or replace package pkg_type is
typy refcur is ref curser
end pkg_type;create or replace function f_getinfo
(
i_o_result out number;
)
return pkg_type.refcur
as
cur_result pkg_type.refcur
ntbl_l_orderid array_number := array_number();update t_config
set configvalue = 7
where configtype = 1
returnning configid
bulk collect
into ntbl_l_orderid;open cur_result for
select t.configid,t.congfigname,t.configtype
from t_config
where configid in (
select cloumn_value from table(
cast(ntbl_l_orderid as array_number))
)commit;
return cur_result上面就是关键部分的代码,首先确定一点,编译是通过的,执行到into ntbl_l_orderid的时候,ntbl_l_orderid是有值的,这点可以确定。
现在的问题是:
select cloumn_value from table(
cast(ntbl_l_orderid as array_number)
这里不能获取到值。导致最后的游标为空。不知道是转换还是什么的问题,请大家帮忙看下
还有一点,如果不用cast会报错,这是为什么呢?
直接用select * from TABLE(l_data) 呢
2 /
Type created
SQL>
SQL> create or replace function test_table
2 return arry_number
3 as
4 l_data arry_number := arry_number();
5 begin
6 select empno bulk collect into l_data from emp;
7 return l_data;
8 end;
9 /
Function created
SQL> select column_value from table(test_table);
COLUMN_VALUE
------------
7369
7499
7521
7566
7654
7698
7782
7788
7839
7844
7876
7900
7902
7934
14 rows selected
SQL>
SQL> create or replace procedure proc_test_table
2 as
3 l_data arry_number := arry_number();
4 v_num number(20);
5 c1 sys_refcursor;
6 begin
7 update emp set empno=empno
8 returning empno
9 bulk collect
10 into l_data ;
11 open c1 for
12 select column_value from table(l_data);
13 loop
14 fetch c1 into v_num;
15 exit when c1%notfound;
16 dbms_output.put_line(v_num);
17 end loop;
18 end;
19 /
Procedure created
SQL> set serveroutput on
SQL> execute proc_test_table
7369
7499
7521
7566
7654
7698
7782
7788
7839
7844
7876
7900
7902
7934
PL/SQL procedure successfully completed
SQL>
所以我一直很奇怪。是由于oracle的版本问题吗?我用的9i,
cast(ntbl_l_orderid as array_number))这个语句在执行的时候我看了下ntbl_l_orderid里有数据的。我有PL/SQL看的,值的类型的是
index value
1 222
2 232
3 242
数据是有了。就是cast或者select 的时候查不到。很纠结。。