I want to create a simple procedure that when passed a primary key will delete a record from a table.
I have read this thread about SQL%NOTFOUND. I think that the solution for that problem is to use a function that checks that the parameter passed is a primary key of that table and returns a boolean. I’m sure that there are more things to look out for here though.
What other problems or specific exceptions should I look for?
Here is the basic template for my procedure:
create or replace procedure delete_employee
( employee_id_i in employees.employee_id%type) is
begin
if valid_employee(employee_id_i) then
delete from employees where employee_id = employee_id_i;
end if;
exception
when others then
log_error_proc(dbms_utility.format_error_stack(),
dbms_utility.format_error_backtrace());
end delete_employees;
You should use the
ROWCOUNTattribute of the implicit cursor instead. This will return the number of affected rows from theDELETEstatement, and saves you from having to query the table in yourvalid_employeefunction.