Académique Documents
Professionnel Documents
Culture Documents
Use the WHERE CURRENT OF clause to reference the current row from an explicit cursor.
When referencing the current row from an explicit cursor, use the WHERE CURRENT OF clause. This
allows you to apply updates and deletes to the row currently being addressed, without the need to
explicitly reference the ROWID. You must include the FOR UPDATE clause in the cursor query so that the
rows are locked on OPEN.
DECLARE
CURSOR sal_cursor IS
SELECT e.department_id, employee_id, last_name, salary
FROM employees e, departments d
WHERE d.department_id = e.department_id
and d.department_id = 60
FOR UPDATE OF salary NOWAIT;
BEGIN
FOR emp_record IN sal_cursor
LOOP
IF emp_record.salary < 5000 THEN
UPDATE employees
SET salary = emp_record.salary * 1.10
WHERE CURRENT OF sal_cursor;
END IF;
END LOOP;
END;
Begin the exception-handling section of the block with the EXCEPTION keyword.
Define several exception handlers, each with its own set of actions, for the block.
When an exception occurs, PL/SQL processes only one handler before leaving the block.
Place the OTHERS clause after all other exception-handling clauses.
You can have only one OTHERS clause.
Exceptions cannot appear in assignment statements or SQL statements.
When the exception propagates to an enclosing block, the remaining executable actions in that block
are bypassed.
The RAISE_APPLICATION_ERROR Procedure
You can use this procedure to issue user-defined error messages from stored subprograms.
You can report errors to your application and avoid returning unhandled exceptions.
Used in two different places:
Executable section
Exception section
Returns error conditions to the user in a manner consistent with other Oracle server errors.
Executable section:
BEGIN
...
DELETE FROM employees
WHERE manager_id = v_mgr;
IF SQL%NOTFOUND THEN
RAISE_APPLICATION_ERROR(-20202,
This is not a valid manager);
END IF;
Exception section:
...
EXCEPTION
WHEN NO_DATA_FOUND THEN
RAISE_APPLICATION_ERROR (-20201,
Manager is not a valid employee.);
END;
Positional :- Lists values in the order in which the parameters are declared
Named association:- Lists values in arbitrary order by associating each one with its parameter name,
using special syntax (=>)
Combination Lists:- the first values positionally, and the remainder using the special syntax of the
named method