oracle - no_data_found 时出现异常,我想将两个变量分配给 null
问题描述
我编写了一个选择查询来获取两个列值,以防出现异常,我想在 ORACLE STORED PROCEDURE 中将这些变量分配给 null。
例如:
select column A, column B into l_a, l_b
from ......
exception
when no_data_found then
l_a: = null and l_b := null ;
解决方案
有一个错字。它必须:=
代替: =
. 您还需要用分号分隔语句:;
。通常语句在单独的行中。
l_a := null;
l_b := null;
除此之外,您不需要分配 null。变量最初被分配为空,如果没有找到数据,它们将保持为空。
当然,如果变量在值保持之前被分配了一个值。所以你也可以这样做。
l_a := null;
l_b := null;
select column A, column B into l_a, l_b
from ......
-- do something with l_a and l_b here
exception
when no_data_found then
null; -- ignore and do nothing
但通往罗马的道路总是有很多
推荐阅读
- python - 从 Dask DataFrame (tensorflow_decision_forests) 创建 Keras 数据集
- javascript - 如何将字符串转换为数组 (JavaScript)
- android - 参数类型'流
' 不能分配给参数类型 'Stream ? - reactjs - axios cancelToken 中使用效果清理
- c++ - 如何将 std::unordered_map 部分专门化为我的模板类的成员?
- python - 如何在 Docker 上升级 pip 的 setuptools?
- laravel - 无法通过 axios 发送 HTML 字符串
- javascript - 无法获取 document.getElementById。控制台说无法读取属性“null 值”
- git - GitHub Desktop 突然无法获取源,无法推送更改
- css - 用于匹配元素的 CSS 规则不跟随特定类的另一个元素