Oracle - 过程相关查询

发布于 2024-08-05 05:00:13 字数 212 浏览 3 评论 0原文

我在 oracle 中编写以下查询:

DBMS_OUTPUT.....'Ashish'

Select col1 into val1 from tab_1

DBMS_OUTPUT.....'Ubale'

当我运行此过程时,我得到的输出为“Ashish”,为什么? 还有 v_val1 变量的值是什么

注意:该表不包含任何记录

I am writing the below queries in oracle:

DBMS_OUTPUT.....'Ashish'

Select col1 into val1 from tab_1

DBMS_OUTPUT.....'Ubale'

when I run this procedure I get the output as "Ashish" only why?
also what will be the value of v_val1 variable

Note: the table does not contain any records

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

芯好空 2024-08-12 05:00:13

由于表是空的,“select into”语句将引发 NO_DATA_FOUND 异常。这就是为什么您没有收到第二条消息的原因。 val1 将具有与选择之前相同的值 - 即如果您之前没有分配值,则为 null。

事实上,您不知道自己遇到了 NO_DATA_FOUND 异常,这表明您犯了 PL/SQL 开发人员曾经犯过的最大错误之一:

EXCEPTION
    -- Never do this in real code!!!
   WHEN OTHERS THEN NULL;
END;

Since the table is empty, the "select into" statement will raise the NO_DATA_FOUND exception. That's why you don't get the second message. val1 will have the same value as before the select - i.e. null if you didn't previously assign a value.

The fact that you don't know you got the NO_DATA_FOUND exception suggests that you have made one of the biggest errors PL/SQL developers ever make:

EXCEPTION
    -- Never do this in real code!!!
   WHEN OTHERS THEN NULL;
END;
命硬 2024-08-12 05:00:13

你收到错误了吗?如果表中没有行。您可能会收到 no_data_found 异常。

顺便问一下,你的整个代码在哪里?

Did you get error? If the table doesn't have rows in it. You might get no_data_found exception.

By the way, where is your entire code?

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