更新语句不适用于for Loop

时间:2019-05-30 16:12:31

标签: sql plsql

我需要人们的快速帮助。我有一个过程正在更新表中的某些记录。但是,虽然它正在获取游标中的记录,但是在循环更新语句内部并未执行。

我尝试将dbms_output.put_line放入语句中,但无法打印。

  CURSOR cur_or
  IS
  SELECT DISTINCT c.general_ledger_gid,
                  b.order_release_gid --, c.cost_type
    FROM invoice_shipment a,
         view_shipment_order_release b,
         shipment_cost c
   WHERE a.shipment_gid      = b.shipment_gid
     AND c.shipment_gid        = c.shipment_gid
     AND a.shipment_gid        = c.shipment_gid
     AND a.invoice_gid         = p_invoice_gid
     AND c.general_ledger_gid IS NOT NULL;

  CURSOR cur_orl (lv_ORDER_RELEASE_GID IN VARCHAR2)
  IS
  SELECT d.order_release_line_gid
    FROM order_release_line d
   WHERE order_release_gid = lv_ORDER_RELEASE_GID;

BEGIN
  FOR rec_or IN cur_or
  LOOP
    UPDATE allocation_order_release_d
    SET general_ledger_gid    = rec_or.general_ledger_gid
    WHERE general_ledger_gid IS NULL
    AND order_release_gid     = rec_or.order_release_gid;

    dbms_output.put_line ('a Passed');
    FOR rec_orl IN cur_orl (rec_or.order_release_gid)
    LOOP
      UPDATE allocation_or_line_d
      SET general_ledger_gid     = rec_or.general_ledger_gid
      WHERE general_ledger_gid  IS NULL
      AND order_release_line_gid = rec_orl.order_release_line_gid;

      dbms_output.put_line ('b Passed');
    END LOOP;
    dbms_output.put_line ('c Passed');
  END LOOP;
  dbms_output.put_line ('d Passed');
EXCEPTION
  WHEN NO_DATA_FOUND THEN
    NULL;

它应该在游标获取值时在循环内运行update语句

0 个答案:

没有答案