How do i capture the update column value and use it?











up vote
0
down vote

favorite












Hi I have a scenario where in using a cursor loop getting all the invoice values and checking the details and updating flag values to 'E' if the update validation is satisfied and only inserting those invoices to another table which doesn't satisfy the update statement.



Is there a way by which based on the flag value we can insert those invoices?



Kindly find the Code:



Procedure 
CURSOR c2
IS
SELECT *
FROM invoice_tl
WHERE process_flag = 'N';
BEGIN
FOR rec IN c2
LOOP
BEGIN

fnd_file.put_line (fnd_file.LOG, 'The Line Number is ' || ' ' || rec.line_number);

IF rec.line_number IS NOT NULL
THEN

UPDATE invoice_tl
SET process_flag = 'E',
error_description =
(SELECT 'Credit Memo line amount cannot be more than Invoice Line Amount : '
|| (rctl.extended_amount
- NVL (
(SELECT SUM (amount)
FROM ar_activity_details
WHERE customer_trx_line_id =
rctl.customer_trx_line_id),
0)
+ NVL (
(SELECT SUM (extended_amount)
FROM ra_customer_trx_lines_all
WHERE previous_customer_trx_line_id =
rctl.customer_trx_line_id),
0))
FROM ra_customer_trx_all rct,
ra_customer_trx_lines_all rctl
WHERE rct.customer_trx_id =
rctl.customer_trx_id
AND rct.org_id = 2326
AND rct.trx_number = rec.invoice_number
AND rctl.line_number = rec.line_number
AND rct.cust_trx_type_id =
ln_trans_type_id)
WHERE process_flag = 'N'
AND invoice_number = rec.invoice_number
AND line_number = rec.line_number
AND amount >
(SELECT (rctl.extended_amount
- NVL (
(SELECT SUM (amount)
FROM ar_activity_details
WHERE customer_trx_line_id =
rctl.customer_trx_line_id),
0)
+ NVL (
(SELECT SUM (extended_amount)
FROM ra_customer_trx_lines_all
WHERE previous_customer_trx_line_id =
rctl.customer_trx_line_id),
0))
FROM ra_customer_trx_all rct,
ra_customer_trx_lines_all rctl
WHERE rct.customer_trx_id =
rctl.customer_trx_id
AND rct.org_id = 2326
AND rct.trx_number =
rec.invoice_number
AND rctl.line_number =
rec.line_number
AND rct.cust_trx_type_id =
ln_trans_type_id);

fnd_file.put_line (
fnd_file.LOG,
'Error Message if the CM amount more than the Invoice Line amount.');
COMMIT;
END IF;
END;

BEGIN
fnd_file.put_line (
fnd_file.LOG,
'The Process FLag is : ' || rec.process_flag);
INSERT INTO second_table (
customer_number,
orig_system_cust_reference,
orig_system_add_reference,
customer_name,
locations,
inv_date,
creation_date,
inv_num,
balance_amount,
customer_trx_id,
customer_trx_line_id,
NAME,
term_desc,
term_id,
gl_date,
rec_segments1,
rec_segments2.....
END;
END LOOP;
END









share|improve this question




























    up vote
    0
    down vote

    favorite












    Hi I have a scenario where in using a cursor loop getting all the invoice values and checking the details and updating flag values to 'E' if the update validation is satisfied and only inserting those invoices to another table which doesn't satisfy the update statement.



    Is there a way by which based on the flag value we can insert those invoices?



    Kindly find the Code:



    Procedure 
    CURSOR c2
    IS
    SELECT *
    FROM invoice_tl
    WHERE process_flag = 'N';
    BEGIN
    FOR rec IN c2
    LOOP
    BEGIN

    fnd_file.put_line (fnd_file.LOG, 'The Line Number is ' || ' ' || rec.line_number);

    IF rec.line_number IS NOT NULL
    THEN

    UPDATE invoice_tl
    SET process_flag = 'E',
    error_description =
    (SELECT 'Credit Memo line amount cannot be more than Invoice Line Amount : '
    || (rctl.extended_amount
    - NVL (
    (SELECT SUM (amount)
    FROM ar_activity_details
    WHERE customer_trx_line_id =
    rctl.customer_trx_line_id),
    0)
    + NVL (
    (SELECT SUM (extended_amount)
    FROM ra_customer_trx_lines_all
    WHERE previous_customer_trx_line_id =
    rctl.customer_trx_line_id),
    0))
    FROM ra_customer_trx_all rct,
    ra_customer_trx_lines_all rctl
    WHERE rct.customer_trx_id =
    rctl.customer_trx_id
    AND rct.org_id = 2326
    AND rct.trx_number = rec.invoice_number
    AND rctl.line_number = rec.line_number
    AND rct.cust_trx_type_id =
    ln_trans_type_id)
    WHERE process_flag = 'N'
    AND invoice_number = rec.invoice_number
    AND line_number = rec.line_number
    AND amount >
    (SELECT (rctl.extended_amount
    - NVL (
    (SELECT SUM (amount)
    FROM ar_activity_details
    WHERE customer_trx_line_id =
    rctl.customer_trx_line_id),
    0)
    + NVL (
    (SELECT SUM (extended_amount)
    FROM ra_customer_trx_lines_all
    WHERE previous_customer_trx_line_id =
    rctl.customer_trx_line_id),
    0))
    FROM ra_customer_trx_all rct,
    ra_customer_trx_lines_all rctl
    WHERE rct.customer_trx_id =
    rctl.customer_trx_id
    AND rct.org_id = 2326
    AND rct.trx_number =
    rec.invoice_number
    AND rctl.line_number =
    rec.line_number
    AND rct.cust_trx_type_id =
    ln_trans_type_id);

    fnd_file.put_line (
    fnd_file.LOG,
    'Error Message if the CM amount more than the Invoice Line amount.');
    COMMIT;
    END IF;
    END;

    BEGIN
    fnd_file.put_line (
    fnd_file.LOG,
    'The Process FLag is : ' || rec.process_flag);
    INSERT INTO second_table (
    customer_number,
    orig_system_cust_reference,
    orig_system_add_reference,
    customer_name,
    locations,
    inv_date,
    creation_date,
    inv_num,
    balance_amount,
    customer_trx_id,
    customer_trx_line_id,
    NAME,
    term_desc,
    term_id,
    gl_date,
    rec_segments1,
    rec_segments2.....
    END;
    END LOOP;
    END









    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      Hi I have a scenario where in using a cursor loop getting all the invoice values and checking the details and updating flag values to 'E' if the update validation is satisfied and only inserting those invoices to another table which doesn't satisfy the update statement.



      Is there a way by which based on the flag value we can insert those invoices?



      Kindly find the Code:



      Procedure 
      CURSOR c2
      IS
      SELECT *
      FROM invoice_tl
      WHERE process_flag = 'N';
      BEGIN
      FOR rec IN c2
      LOOP
      BEGIN

      fnd_file.put_line (fnd_file.LOG, 'The Line Number is ' || ' ' || rec.line_number);

      IF rec.line_number IS NOT NULL
      THEN

      UPDATE invoice_tl
      SET process_flag = 'E',
      error_description =
      (SELECT 'Credit Memo line amount cannot be more than Invoice Line Amount : '
      || (rctl.extended_amount
      - NVL (
      (SELECT SUM (amount)
      FROM ar_activity_details
      WHERE customer_trx_line_id =
      rctl.customer_trx_line_id),
      0)
      + NVL (
      (SELECT SUM (extended_amount)
      FROM ra_customer_trx_lines_all
      WHERE previous_customer_trx_line_id =
      rctl.customer_trx_line_id),
      0))
      FROM ra_customer_trx_all rct,
      ra_customer_trx_lines_all rctl
      WHERE rct.customer_trx_id =
      rctl.customer_trx_id
      AND rct.org_id = 2326
      AND rct.trx_number = rec.invoice_number
      AND rctl.line_number = rec.line_number
      AND rct.cust_trx_type_id =
      ln_trans_type_id)
      WHERE process_flag = 'N'
      AND invoice_number = rec.invoice_number
      AND line_number = rec.line_number
      AND amount >
      (SELECT (rctl.extended_amount
      - NVL (
      (SELECT SUM (amount)
      FROM ar_activity_details
      WHERE customer_trx_line_id =
      rctl.customer_trx_line_id),
      0)
      + NVL (
      (SELECT SUM (extended_amount)
      FROM ra_customer_trx_lines_all
      WHERE previous_customer_trx_line_id =
      rctl.customer_trx_line_id),
      0))
      FROM ra_customer_trx_all rct,
      ra_customer_trx_lines_all rctl
      WHERE rct.customer_trx_id =
      rctl.customer_trx_id
      AND rct.org_id = 2326
      AND rct.trx_number =
      rec.invoice_number
      AND rctl.line_number =
      rec.line_number
      AND rct.cust_trx_type_id =
      ln_trans_type_id);

      fnd_file.put_line (
      fnd_file.LOG,
      'Error Message if the CM amount more than the Invoice Line amount.');
      COMMIT;
      END IF;
      END;

      BEGIN
      fnd_file.put_line (
      fnd_file.LOG,
      'The Process FLag is : ' || rec.process_flag);
      INSERT INTO second_table (
      customer_number,
      orig_system_cust_reference,
      orig_system_add_reference,
      customer_name,
      locations,
      inv_date,
      creation_date,
      inv_num,
      balance_amount,
      customer_trx_id,
      customer_trx_line_id,
      NAME,
      term_desc,
      term_id,
      gl_date,
      rec_segments1,
      rec_segments2.....
      END;
      END LOOP;
      END









      share|improve this question















      Hi I have a scenario where in using a cursor loop getting all the invoice values and checking the details and updating flag values to 'E' if the update validation is satisfied and only inserting those invoices to another table which doesn't satisfy the update statement.



      Is there a way by which based on the flag value we can insert those invoices?



      Kindly find the Code:



      Procedure 
      CURSOR c2
      IS
      SELECT *
      FROM invoice_tl
      WHERE process_flag = 'N';
      BEGIN
      FOR rec IN c2
      LOOP
      BEGIN

      fnd_file.put_line (fnd_file.LOG, 'The Line Number is ' || ' ' || rec.line_number);

      IF rec.line_number IS NOT NULL
      THEN

      UPDATE invoice_tl
      SET process_flag = 'E',
      error_description =
      (SELECT 'Credit Memo line amount cannot be more than Invoice Line Amount : '
      || (rctl.extended_amount
      - NVL (
      (SELECT SUM (amount)
      FROM ar_activity_details
      WHERE customer_trx_line_id =
      rctl.customer_trx_line_id),
      0)
      + NVL (
      (SELECT SUM (extended_amount)
      FROM ra_customer_trx_lines_all
      WHERE previous_customer_trx_line_id =
      rctl.customer_trx_line_id),
      0))
      FROM ra_customer_trx_all rct,
      ra_customer_trx_lines_all rctl
      WHERE rct.customer_trx_id =
      rctl.customer_trx_id
      AND rct.org_id = 2326
      AND rct.trx_number = rec.invoice_number
      AND rctl.line_number = rec.line_number
      AND rct.cust_trx_type_id =
      ln_trans_type_id)
      WHERE process_flag = 'N'
      AND invoice_number = rec.invoice_number
      AND line_number = rec.line_number
      AND amount >
      (SELECT (rctl.extended_amount
      - NVL (
      (SELECT SUM (amount)
      FROM ar_activity_details
      WHERE customer_trx_line_id =
      rctl.customer_trx_line_id),
      0)
      + NVL (
      (SELECT SUM (extended_amount)
      FROM ra_customer_trx_lines_all
      WHERE previous_customer_trx_line_id =
      rctl.customer_trx_line_id),
      0))
      FROM ra_customer_trx_all rct,
      ra_customer_trx_lines_all rctl
      WHERE rct.customer_trx_id =
      rctl.customer_trx_id
      AND rct.org_id = 2326
      AND rct.trx_number =
      rec.invoice_number
      AND rctl.line_number =
      rec.line_number
      AND rct.cust_trx_type_id =
      ln_trans_type_id);

      fnd_file.put_line (
      fnd_file.LOG,
      'Error Message if the CM amount more than the Invoice Line amount.');
      COMMIT;
      END IF;
      END;

      BEGIN
      fnd_file.put_line (
      fnd_file.LOG,
      'The Process FLag is : ' || rec.process_flag);
      INSERT INTO second_table (
      customer_number,
      orig_system_cust_reference,
      orig_system_add_reference,
      customer_name,
      locations,
      inv_date,
      creation_date,
      inv_num,
      balance_amount,
      customer_trx_id,
      customer_trx_line_id,
      NAME,
      term_desc,
      term_id,
      gl_date,
      rec_segments1,
      rec_segments2.....
      END;
      END LOOP;
      END






      oracle plsql oracle-sqldeveloper oracle12c plsqldeveloper






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 23 at 9:52

























      asked Nov 22 at 11:33









      NerdFredrick

      61




      61
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          Your best bet is to use the RETURNING INTO clause. So you'll define an array and capture the appropriate parts of the updated rows:



          declare
          type line_number_tt is table of invoice_tl.line_number%TYPE;
          line_number_array line_number_tt;
          begin
          ....

          update invoice_tl
          ...
          returning line_number bulk collect into line_number_array;

          [do stuff with the array here]
          end;


          I would really try to get rid of the select-then-loop you have, if you can. That's row by row processing and there's a reason it's called "slow-by-slow."






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53430049%2fhow-do-i-capture-the-update-column-value-and-use-it%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            Your best bet is to use the RETURNING INTO clause. So you'll define an array and capture the appropriate parts of the updated rows:



            declare
            type line_number_tt is table of invoice_tl.line_number%TYPE;
            line_number_array line_number_tt;
            begin
            ....

            update invoice_tl
            ...
            returning line_number bulk collect into line_number_array;

            [do stuff with the array here]
            end;


            I would really try to get rid of the select-then-loop you have, if you can. That's row by row processing and there's a reason it's called "slow-by-slow."






            share|improve this answer

























              up vote
              0
              down vote













              Your best bet is to use the RETURNING INTO clause. So you'll define an array and capture the appropriate parts of the updated rows:



              declare
              type line_number_tt is table of invoice_tl.line_number%TYPE;
              line_number_array line_number_tt;
              begin
              ....

              update invoice_tl
              ...
              returning line_number bulk collect into line_number_array;

              [do stuff with the array here]
              end;


              I would really try to get rid of the select-then-loop you have, if you can. That's row by row processing and there's a reason it's called "slow-by-slow."






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                Your best bet is to use the RETURNING INTO clause. So you'll define an array and capture the appropriate parts of the updated rows:



                declare
                type line_number_tt is table of invoice_tl.line_number%TYPE;
                line_number_array line_number_tt;
                begin
                ....

                update invoice_tl
                ...
                returning line_number bulk collect into line_number_array;

                [do stuff with the array here]
                end;


                I would really try to get rid of the select-then-loop you have, if you can. That's row by row processing and there's a reason it's called "slow-by-slow."






                share|improve this answer












                Your best bet is to use the RETURNING INTO clause. So you'll define an array and capture the appropriate parts of the updated rows:



                declare
                type line_number_tt is table of invoice_tl.line_number%TYPE;
                line_number_array line_number_tt;
                begin
                ....

                update invoice_tl
                ...
                returning line_number bulk collect into line_number_array;

                [do stuff with the array here]
                end;


                I would really try to get rid of the select-then-loop you have, if you can. That's row by row processing and there's a reason it's called "slow-by-slow."







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 23 at 20:46









                eaolson

                8,14163145




                8,14163145






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53430049%2fhow-do-i-capture-the-update-column-value-and-use-it%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Contact image not getting when fetch all contact list from iPhone by CNContact

                    count number of partitions of a set with n elements into k subsets

                    A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks