Hi,
I am trying to create a procedure to insert data into a table, by verifying the in parameter against a column value and insert only if that parameter value is found.
In other words, trying to insert unique values into the table column.
This is what I did:
create or replace procedure sh_ins (v_name in varchar2)
as
v_shname varchar2(10);
cursor sh_cur is select sh_name from superheros;
begin
for v_counter in sh_cur loop
if v_counter.sh_name <> v_name then
insert into superheros (sh_name) values (v_name);
commit;
else
dbms_output.put_line('Name Already Exists');
end if;
end loop;
end;
I know I am reading only 1 value at a time in the cursor and as it is not matching with my in parameter, it is inserting. But I want to read all values and compare every single value and then only insert.
I would appreciate if anyone can guide me through this.
Thanks
Rajiv