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;
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);
raise invld;
end if;
when invld then
dbms_output.put_line('You cannot enter value');

Leave a Reply

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