【问题标题】:Convert FOR statement to FORALL in PL/SQL Oracle在 PL/SQL Oracle 中将 FOR 语句转换为 FORALL
【发布时间】:2018-10-08 07:17:43
【问题描述】:

这可以在“forall”中转换这个“for”吗?

FOR  tempCounter in tempCollection.FIRST .. tempCollection.LAST LOOP
  IF tempCollection(tempCounter).execactstockkey IS NULL THEN
    RETURN;
  END IF;
  INSERT INTO  tbexectempactstock VALUES  tempCollection(tempCounter);
END LOOP; 

我也试过了

FORALL tempCounter in tempCollection.FIRST .. tempCollection.LAST
  INSERT WHEN tempCollection(i).execactstockkey IS NOT NULL
    THEN INTO tbexectempactstock VALUES tempCollection(tempCounter);

但它弹出我缺少 SELECT KEYBOARD

【问题讨论】:

    标签: oracle for-loop plsql null forall


    【解决方案1】:

    我怀疑您是否可以将此条件语句转换为FORALL INSERTFORALL MERGE 可能是可能的,但我认为最好的方法是在单个插入中完成:

    INSERT INTO tbexectempactstock
    SELECT * FROM TABLE(tempCollection)
     WHERE execactstockkey IS NOT NULL
    

    【讨论】:

    • 此语法适用于 Oracle Database 12c 之前的对象类型的嵌套表。从 12.1 开始,您还可以将 TABLE 与关联数组一起使用。
    【解决方案2】:

    你可以使用非空子句

       FORALL tempCounter  IN tempCollection.FIRST .. tempCollection.LAST
        INSERT INTO tbexectempactstock 
        SELECT
            *
        FROM TABLE(tempCollection(tempCounter))
        WHERE tempCollection(tempCounter).execactstockkey IS NOT NULL;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-18
      • 2014-03-05
      • 1970-01-01
      • 2019-09-11
      • 2015-09-16
      • 1970-01-01
      • 1970-01-01
      • 2015-12-13
      相关资源
      最近更新 更多