0

In procedure below,I'm updating and inserting into docmeta and documenthistory table respectively. I've calculated the value of 'paymentterm' in docmeta update with code as shown below. Now i want to insert the same paymentterm vale in documenthistory table as well(highlighted in bold and italics below).But since paymenterm in docmeta has limited scope i'm not able to use this value in documenthistory table even if i write the complete paymentterm select statement i.e. SELECT paymentterm FROM temp_pay_term WHERE pid = d.xProject_id AND rownum <= 1

How can i make the code below workable ...................................................................

CREATE OR REPLACE
PROCEDURE PAYTERMUPDATE
IS
  RecordCount INT;
  varDID      NUMBER(38);
BEGIN
  RecordCount :=0;
  SELECT COUNT(1)
  INTO RecordCount
  FROM temp_pay_term;
  IF RecordCount > 0 THEN
    FOR X       IN
    (SELECT DISTINCT r.ddocName
    FROM temp_Pay_Term ptq,
      docMeta d,
      revisions r
    WHERE TO_CHAR(ptq.pid) = d.xproject_id
    AND r.did              = d.did
    )
    LOOP
      SELECT MAX(did)
      INTO varDid
      FROM revisions r
      WHERE r.ddocname = X.ddocName
      GROUP BY r.ddocname;
      UPDATE docmeta d
      SET paymentterm =
        (SELECT paymentterm
        FROM temp_pay_term
        WHERE pid   = d.xProject_id
        AND rownum <= 1
        )
      WHERE d.did = vardid;
      INSERT
      INTO DOCUMENTHISTORY
        (
          dactionmillis,
          dactiondate,
          did,
          drevclassid,
          duser,
          ddocname,
          daction,
          dsecuritygroup,
          ***paymentterm***
        )
      SELECT to_number(TO_CHAR(systimestamp,'FF')) AS dactionmillis,
        TRUNC(systimestamp,'dd')                   AS dactiondate,
        did,
        drevclassid,
        'sysadmin' AS duser,
        ddocname,
        'Update' AS daction,
        dsecuritygroup,
        ***PAYMENTTERM***
      FROM revisions
      WHERE did = vardid;
    END LOOP;
    COMMIT;
  END IF;
END PAYTERMUPDATE; -- PL SQL code

1 Answer 1

0

If I get it right, you can return paymentterm using returning into

  declare
    ...
    varpayment number;
  begin
    ...

    update docmeta d
    set paymentterm =
        (select paymentterm
         from temp_pay_term
         where pid = d.xproject_id
           and rownum <= 1)
    where d.did = vardid
    returning paymentterm into varpayment;

    /* and then use varpayment */
    ... 
  end;

See returning into documentation for more details

4
  • Thanks Simon. It compiled successfully but is the procedure correct? I'm still not getting values in my tables. OR am I still missing something? Jan 10, 2014 at 9:23
  • if you do not get both values on your tables, could this mean your subquery select paymentterm from temp_pay_term where pid = d.xproject_id and rownum <= 1 returns no rows or null?
    – smnbbrv
    Jan 10, 2014 at 9:34
  • Right. rownum <= 1 is creating the issue Jan 10, 2014 at 10:02
  • I'm getting below error while executing this procedure.Am i getting multiple values in this select and returning is not accepting it is the issue? Does returning takes multiple values. 'If Not', how can we allow multiple rows here.ORA-01427: single-row subquery returns more than one row ORA-06512: at "ITAPP_STELLENT_DELFIN16.PAYTERMUPDATE", line 31 ORA-06512: at line 1 Jan 17, 2014 at 6:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.