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!

cursor for loop with no_data_found

AB115Jun 29 2019 — edited Jul 1 2019

Hello experts,

we have below scenario by using cursor for loop but exception is not getting generated and no message is getting displayed,

Oracle Version:11.2.0.1

statements:

create table emp_test (emp_id number, emp_name varchar2(20))

/

create table dep_test (emp_id number, emp_name varchar2(20))

/

insert into emp_test values (1,'ABC')

/

insert into emp_test values (2,'DEF')

/

insert into emp_test values (3,'MNP')

/

insert into emp_test values (4,'PQR')

/

insert into emp_test values (5,'XYZ')

/

commit

/

Script:

set serveroutput on;

DECLARE

    CURSOR c1

    IS

        SELECT emp_id, emp_name

          FROM emp_test

         WHERE emp_id = 6;

BEGIN

    FOR c1_rec IN c1

    LOOP

        INSERT INTO dep_test

             VALUES (c1_rec.emp_id, c1_rec.emp_name);

    END LOOP;

    COMMIT;

EXCEPTION

    WHEN NO_DATA_FOUND

    THEN

        DBMS_OUTPUT.put_line (SQLCODE || SQLERRM);

END;

Please suggest.

Thanks.

This post has been answered by mathguy on Jun 30 2019
Jump to Answer
Comments
Post Details
Added on Jun 29 2019
23 comments
26,127 views