如果EXISTS条件不适用于PLSQL

编程入门 行业动态 更新时间:2024-10-13 20:17:27
本文介绍了如果EXISTS条件不适用于PLSQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试在条件为TRUE时打印TEXT。选择代码完全正常工作。当我只运行选择代码时,它显示403值。但是当条件存在时我必须打印一些文本。以下代码有什么问题。

I am trying to print the TEXT when condition is TRUE. The select code is perfectly working fine. It's showing 403 value when i only run select code. But I have to print some text when condition exists. What's the problem with following code.

BEGIN IF EXISTS( SELECT CE.S_REGNO FROM COURSEOFFERING CO JOIN CO_ENROLMENT CE ON CE.CO_ID = CO.CO_ID WHERE CE.S_REGNO=403 AND CE.COE_COMPLETIONSTATUS = 'C' AND CO.C_ID = 803 ) THEN DBMS_OUTPUT.put_line('YES YOU CAN'); END;

以下是错误报告:

Error report: ORA-06550: line 5, column 1: PLS-00103: Encountered the symbol "JOIN" when expecting one of the following: ) , with group having intersect minus start union where connect 06550. 00000 - "line %s, column %s:\n%s" *Cause: Usually a PL/SQL compilation error. *Action:

推荐答案

IF EXISTS()在语义上是不正确的。 EXISTS 条件只能在SQL语句中使用。因此,您可以按如下方式重写pl / sql块:

IF EXISTS() is semantically incorrect. EXISTS condition can be used only inside a SQL statement. So you might rewrite your pl/sql block as follows:

declare l_exst number(1); begin select case when exists(select ce.s_regno from courseoffering co join co_enrolment ce on ce.co_id = co.co_id where ce.s_regno=403 and ce.coe_completionstatus = 'C' and ce.c_id = 803 and rownum = 1 ) then 1 else 0 end into l_exst from dual; if l_exst = 1 then DBMS_OUTPUT.put_line('YES YOU CAN'); else DBMS_OUTPUT.put_line('YOU CANNOT'); end if; end;

或者你可以简单地使用 count 函数做确定查询返回的行数, rownum = 1 谓词 - 您只需要知道是否存在记录:

Or you can simply use count function do determine the number of rows returned by the query, and rownum=1 predicate - you only need to know if a record exists:

declare l_exst number; begin select count(*) into l_exst from courseoffering co join co_enrolment ce on ce.co_id = co.co_id where ce.s_regno=403 and ce.coe_completionstatus = 'C' and ce.c_id = 803 and rownum = 1; if l_exst = 0 then DBMS_OUTPUT.put_line('YOU CANNOT'); else DBMS_OUTPUT.put_line('YES YOU CAN'); end if; end;

更多推荐

如果EXISTS条件不适用于PLSQL

本文发布于:2023-10-26 17:40:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1530869.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不适用于   条件   EXISTS   PLSQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!