开发中在Oracle中写了一个函数,后来用户有要求,一部分特定的客户走特定的逻辑,除去这些特定客户,其他的还是走旧的逻辑,于是在函数内加了如下的判断
if customerno in (select customerno from tablename where ...) then
...;
end if;
接下来提交就一直报错:PLS-00405,在此上下文中不允许使用子查询
查了一下资料,Oracle不允许在if逻辑判断内使用子查询 in (select …from …)
于是直接在函数内先获取customerno后使用select count,通过判断count来替换之前的逻辑判断
select count(1) into customernocount from tablename where xxx = customerno;
...
if customernocount >0
...;
end if;
至此,问题解决。