PL/SQL Procedure to Add Records without Duplication

PL/SQL Procedure to Add Records without Duplication:

create or replace procedure add_rc (vcity in varchar,vid in number)is
cnt1 number;
cnt2 number;
invld exception;
begin
select count(*) into cnt1 from addr where id=vid;
select count(*) into cnt2 from addr where city=vcity;
if(cnt1=0 and cnt2=0) then
insert into addr values(vcity,vid);
else
raise invld;
end if;
exception
when invld then
dbms_output.put_line('You cannot enter value');
end;

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.