oracle - PLSQL forall 中遇到符号“IF”
问题描述
if statments in forall 是否可以使用,当尝试得到错误PLS-00103: Encountered the symbol "IF" when expecting 以下之一时:. ( * @ % & - + / 在 mod 余数 rem 选择更新与
FORALL i IN 1 .. P_DAYS_IDS.COUNT
if (P_DAYS_IDS(i) = 1) then
Update test set col_1 = 'Y' where id = 1;
elsif (P_DAYS_IDS(i) = 2) then
Update test set col_2 = 'Y' where id = 2;
end if;
解决方案
不 forall
存在以消除 SQL 和 PL/SQL 之间的上下文转换,因此它仅在您使用集合的每个元素执行单个 SQL 操作时才有效。
如果要在循环中执行 PL/SQL 代码,可以使用常规for
循环。
FOR i IN 1 .. P_DAYS_IDS.COUNT
LOOP
if (P_DAYS_IDS(i) = 1) then
Update test set col_1 = 'Y' where id = 1;
elsif (P_DAYS_IDS(i) = 2) then
Update test set col_2 = 'Y' where id = 2;
end if;
end loop;
推荐阅读
- django - 使用 DRF create api 显示外键
- c# - 迁移是单独创建数据库,而不是表
- java - 字符串中带有反斜杠的正则表达式不起作用
- semantic-release - 我在 `master` 分支上的构建使用语义发布运行了两次
- react-native - 根据动态值选择 RadioButton
- angular - 与 IOS 和 Android Nativescript 的深度链接
- sql-server - 为零(“0”)的记录生成主键
- r - 合并 3 个彼此不同的数据帧
- css - :before 伪类会影响 SVG 中的 tspan 吗?
- android - 是否可以在 Android Studio 项目中运行宏?