首页 > 解决方案 > 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;

标签: oracleplsql

解决方案


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;

推荐阅读