为什么我在 PL/SQL 中执行 CASE 语句时收到 ORA-06592: CASE not found?
我在 PL/SQL 中有以下情况
CASE
WHEN v_line_item.custom_segment = 'CND1' THEN
v_current_col := v_col_lcy_tps;
WHEN v_line_item.custom_segment = 'CND2' THEN
v_current_col := v_col_lcy_ib;
WHEN v_line_item.custom_segment = 'CND3' THEN
v_current_col := v_col_lcy_gm;
WHEN v_line_item.custom_segment = 'CND4' THEN
v_current_col := v_col_lcy_pb;
WHEN v_line_item.custom_segment = 'CND5' THEN
v_current_col := v_col_lcy_bb;
END CASE;
代码编译正常,但是当我执行存储过程时出现以下错误:
ORA-06592: 执行 CASE 语句时未找到 CASE
因此,当我删除 CASE 时;存储过程将无法编译。我能得到的唯一示例是在 select 语句中使用 CASE,我不想在 select 语句中使用它,我想在没有一堆 IF THEN ELSE 语句的情况下设置我的变量。
I have the following CASE in PL/SQL
CASE
WHEN v_line_item.custom_segment = 'CND1' THEN
v_current_col := v_col_lcy_tps;
WHEN v_line_item.custom_segment = 'CND2' THEN
v_current_col := v_col_lcy_ib;
WHEN v_line_item.custom_segment = 'CND3' THEN
v_current_col := v_col_lcy_gm;
WHEN v_line_item.custom_segment = 'CND4' THEN
v_current_col := v_col_lcy_pb;
WHEN v_line_item.custom_segment = 'CND5' THEN
v_current_col := v_col_lcy_bb;
END CASE;
The code compiles fine, but when I execute to stored proc I get the following error:
ORA-06592: CASE not found while executing CASE statement
So when I remove the CASE; the stored proc won't compile. The only Examples I can get my hands on, uses the CASE in a select statement, I don't want to use it in select statement, I want to set my variable without having a bunch of IF THEN ELSE statements.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用
CASE
语句 -CASE
下的列表 - 必须匹配您可能遇到的所有条件 - 可以像您通过使用或通过使用
所做的那样显式匹配>ELSE
子句。您的代码遇到了
v_line_item.custom_segment
与任何给定的CASE
场景都不匹配的情况,因此 Oracle 引发了此异常。您可以添加一个包罗万象的条件,
以便它匹配所有条件。
进一步阅读:
If you use a
CASE
statement - the listings under theCASE
- must match all conditions that you might encounter - either explicitly as you have done by usingor by using the
ELSE
clause.Your code is hitting a situation where
v_line_item.custom_segment
doesn't match any of the givenCASE
scenarios, hence Oracle raises this exception.You could add a catch-all condition
so that it matches all conditions.
Further reading:
我知道老线程,但你不就这样写吗?
它更加简洁和可读,并且不会给出 ORA-06592 错误。
Old thread I know, but wouldn't you just write it like this?
It's more concise and readable and it won't give an ORA-06592 error.