在CURSOR中:预期 - 得到了CURSOR

时间:2018-01-30 17:32:41

标签: oracle plsql

为什么函数中的以下代码调用会产生此错误?

SELECT table0.data
FROM table0
WHERE table0.id IN (SELECT cursor FROM dual);

虽然SELECT cursor FROM dual可以在命令行上运行吗?

1 个答案:

答案 0 :(得分:2)

虽然SQL * Plus和PL / SQL Developer等客户端能够处理从查询返回的引用游标,如下所示:

select cursor(select 'X' as txt from dual)
from   dual;

SQL where子句要求表达式解析为值或子查询,而不是游标表达式:

select * from dual
where  dummy in 
       ( select cursor(select 'X' as txt from dual)
         from dual );

ERROR at line 3:
ORA-22902: CURSOR expression not allowed

select * from dual
where  dummy in ( cursor(select 'X' as txt from dual) );

ERROR at line 2:
ORA-22902: CURSOR expression not allowed

如果尝试替换返回引用游标的函数,则会出现类似错误(此处testcursor()是一个返回引用游标的函数):

select * from dual
where  dummy in testcursor();

ERROR at line 2:
ORA-00932: inconsistent datatypes: expected - got CURSOR

这不是where条款处理的事情。