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!

Exception NO_DATA_FOUND in Procedure

xiobijaphJan 21 2019 — edited Jan 22 2019

Hi,
I want create exception 'no_data_found' in procedure but I dont know why it doesn't work:

create table player (p_name VARCHAR2(20), p_surname VARCHAR2(20));

/

insert into player values ('Jerry','Nowak');

/

CREATE PROCEDURE p_test IS

new_p_name VARCHAR2(20) :='Michael';

BEGIN

UPDATE player

SET p_imie=new_p_name WHERE p_surname='Kowalski';

EXCEPTION

WHEN no_data_found then

dbms_output.put_line('bad surname');

end;

/

SET SERVEROUTPUT ON

/

execute p_test;

/

I did it without procedure and here is ok:

create table player (p_name VARCHAR2(20), p_surname VARCHAR2(20));

/

insert into player values ('Jerry','Nowak');

/

SET SERVEROUTPUT ON

/

DECLARE

v_name player.p_name%TYPE;

BEGIN

Select p_name INTO v_name FROM player Where p_surname='Kowalski';

EXCEPTION

WHEN no_data_found then

dbms_output.put_line('Bad surname');

end;

/

This post has been answered by L. Fernigrini on Jan 21 2019
Jump to Answer

Comments

Post Details

Added on Jan 21 2019
13 comments
4,907 views