问题描述
我有一个函数,它在打开游标之前具有三个 If/Then 语句.If/Then 语句在打开游标之前检查有效性.
I have a function which has three If/Then statements before opening a cursor. The If/Then statements check validity prior to opening the cursor.
我想再添加一个 If/Then 有效性检查,但是,它比其他的要复杂一些.下面是一个示例,我已经阻止评论了我想添加的内容:
I would like to add one more If/Then validity check, however, it is a bit more complicated than the others. Below is a sample, and I have block commented what I would like to add:
我的问题是我来自 T-SQL 世界,我发现在 PL/SQL 中 if not exists 命令不起作用.有没有办法可以从函数内部使用 If NO_DATA_FOUND 语句来使用 SELECT?
My problem is that I come from a T-SQL world, and I am finding in PL/SQL the if not exists command does not work. Is there a way I can, from within the function, have an If NO_DATA_FOUND statement where I utilize SELECT?
有没有办法在其中嵌套另一个函数,以便我可以:
Is there a way to nest another function within that, so I can:
推荐答案
Exists
条件只能在 SQL 语句中使用,不能在 PL/SQL 中直接使用.有几个选项:
Exists
condition can be used only in SQL statement, it cannot be used directly in PL/SQL. There are several options:
在
select
语句中使用case
表达式和exists
条件:
Using
case
expression withexists
condition inside aselect
statement:
Or(需要rownum
,保证多条记录满足匹配条件,只返回一条记录):
Or (rownum
is needed to guarantee that the only one record will be returned if there are several records meet matching condition):
这篇关于IF NOT EXISTS 在函数 PLSQL 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!