我试图在 IN 子句中对我的过程使用一组输入值,作为游标的 where 子句的一部分。我知道以前有人问过这个问题,但我还没有看到如何正确编译我的语法。
在包规范中,类型是
TYPE t_brth_dt IS TABLE OF sourceTable.stdt_brth_dt%TYPE INDEX BY PLS_INTEGER;
sourceTable.std_brth_dt
是表中的日期列。我的光标的简化版本在包体中是 -
cursor DataCursor_Sort( p_brth_dt in t_brth_dt) is
SELECT *
FROM sourceTable
WHERE a.brth_dt IN (select column_value
from table(p_brth_dt))
当我尝试编译它时,出现以下错误。
- [1]:(Error): PLS-00382: expression is of wrong type
- [2]:(Error): PL/SQL: ORA-22905: cannot access rows from a non-nested table item
我知道这看起来与其他问题相似,但我不明白语法错误是什么。
最佳答案
为了在 from
中使用定义为嵌套表或关联数组的集合查询的子句,正如@Alex Poole 正确指出的那样,您应该创建一个模式级别 (SQL) 类型或使用一个,您可以通过 ODCIConst
使用该类型。包 - odcidatelist
因为您打算使用日期列表。例如,您的游标定义可能如下所示:
cursor DataCursor_Sort(p_brth_dt in sys.odcidatelist) is
select *
from sourceTable
where a.brth_dt IN (select column_value
from table(p_brth_dt))
或者
cursor DataCursor_Sort(p_brth_dt in sys.odcidatelist) is
select s.*
from sourceTable s
join table(p_brth_dt) t
on (s.brth_dt = t.column_value)
注意:在执行日期比较时,您应该考虑日期的时间部分。如果您只想比较日期部分,使用
trunc()
去掉时间部分可能会很有用。功能。
关于oracle - PL/SQL - 如何在 IN 子句中使用数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18989249/