Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to display no records found in output on cursor

BommiFeb 13 2018 — edited Feb 20 2018

Hi Experts,

     I wrote a query as below

SET SERVEROUTPUT ON;

DECLARE

     CURSOR c_inv

     IS

          SELECT     api.invoice_num,api.creation_date,api.invoice_id

                    ,api.last_updated_by,api.last_update_login,api.gl_date

          FROM      AP_INVOICES_ALL api

                    ,AP_BATCHES_ALL apb

          WHERE      1=1

          AND        apb.batch_id=api.batch_id

          AND        apb.batch_name='5Feb2018-Btch1'

          AND        api.cancelled_date IS NULL;

BEGIN

     DBMS_OUTPUT.PUT_LINE ('Start of Block');

     FOR c_inv_r IN c_inv

     LOOP

          DBMS_OUTPUT.PUT_LINE('Invoice# '||c_inv_r.invoice_num);

     END LOOP;

     DBMS_OUTPUT.PUT_LINE ('End of Block');

EXCEPTION

     WHEN OTHERS THEN

          DBMS_OUTPUT.PUT_LINE ('Error: '||SQLERRM);

END;

     I need to display output as 'No invoices found for given batch' if that batch has no invoices. Can any one please help me on how to achieve this using FOR LOOP.

Thanks in Advance,

Bommi

This post has been answered by John Thorton on Feb 13 2018
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 20 2018
Added on Feb 13 2018
16 comments
551 views