为什么我在 PL/SQL 中执行 CASE 语句时收到 ORA-06592: CASE not found?

发布于 2024-12-01 21:11:43 字数 825 浏览 1 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我的奇迹 2024-12-08 21:11:43

如果您使用 CASE 语句 - CASE 下的列表 - 必须匹配您可能遇到的所有条件 - 可以像您通过使用

WHEN v_line_item.custom_segment = 'CND1' THEN
            v_current_col := v_col_lcy_tps;
WHEN v_line_item.custom_segment = 'CND2' THEN

或通过使用 所做的那样显式匹配>ELSE 子句。

您的代码遇到了 v_line_item.custom_segment 与任何给定的 CASE 场景都不匹配的情况,因此 Oracle 引发了此异常。

您可以添加一个包罗万象的条件,

ELSE
   -- do some work here, raise an exception or log it.

以便它匹配所有条件。

进一步阅读:

If you use a CASE statement - the listings under the CASE - must match all conditions that you might encounter - either explicitly as you have done by using

WHEN v_line_item.custom_segment = 'CND1' THEN
            v_current_col := v_col_lcy_tps;
WHEN v_line_item.custom_segment = 'CND2' THEN

or by using the ELSE clause.

Your code is hitting a situation where v_line_item.custom_segment doesn't match any of the given CASE scenarios, hence Oracle raises this exception.

You could add a catch-all condition

ELSE
   -- do some work here, raise an exception or log it.

so that it matches all conditions.

Further reading:

飘然心甜 2024-12-08 21:11:43

我知道老线程,但你不就这样写吗?

v_current_col :=
    case v_line_item.custom_segment
        when 'CND1' then v_col_lcy_tps
        when 'CND2' then v_col_lcy_ib
        when 'CND3' then v_col_lcy_gm
        when 'CND4' then v_col_lcy_pb
        when 'CND5' then v_col_lcy_bb
    end;

它更加简洁和可读,并且不会给出 ORA-06592 错误。

Old thread I know, but wouldn't you just write it like this?

v_current_col :=
    case v_line_item.custom_segment
        when 'CND1' then v_col_lcy_tps
        when 'CND2' then v_col_lcy_ib
        when 'CND3' then v_col_lcy_gm
        when 'CND4' then v_col_lcy_pb
        when 'CND5' then v_col_lcy_bb
    end;

It's more concise and readable and it won't give an ORA-06592 error.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文