Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Oracle PLSQL遇到了符号“quot;如果;总之_Oracle_Plsql - Fatal编程技术网

Oracle PLSQL遇到了符号“quot;如果;总之

Oracle PLSQL遇到了符号“quot;如果;总之,oracle,plsql,Oracle,Plsql,当尝试获取错误PLS-00103时,是否可以在forall中使用if语句:在预期以下情况之一时遇到符号“if”:。(*@%&-+/at mod rem选择使用更新 否。forall的存在是为了消除SQL和PL/SQL之间的上下文转换,因此它仅在使用集合的每个元素执行单个SQL操作时才有效 如果要在循环中执行PL/SQL代码,可以使用常规的for循环 FOR i IN 1 .. P_DAYS_IDS.COUNT LOOP if (P_DAYS_IDS(i) = 1) then

当尝试获取错误PLS-00103时,是否可以在forall中使用if语句:在预期以下情况之一时遇到符号“if”:。(*@%&-+/at mod rem选择使用更新


否。
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;

您不能在FORALL中使用IF,因为它只需要1个DML,并且SQL中没有IF。但是,测试的条件会迁移到CASE表达式或WHERE子句。为此,您可以将IF谓词和WHERE子句组合到每个可能更新的列的CASE表达式中

forall i in 1 .. p_days_ids.count         
    update test 
       set col_1 =  case when p_days_ids(i) = 1 and id = 1 then 'Y' else col_1 end   
         , col_2 =  case when p_days_ids(i) = 2 and id = 2 then 'Y' else col_2 end; 
请注意,当一列在集合中引用时,需要指定一个值。因此,如果不满足when条件,则只需将该列设置为其当前值

forall i in 1 .. p_days_ids.count         
    update test 
       set col_1 =  case when p_days_ids(i) = 1 and id = 1 then 'Y' else col_1 end   
         , col_2 =  case when p_days_ids(i) = 2 and id = 2 then 'Y' else col_2 end;