DBMS Cursors and Triggers Notes
DBMS Cursors and Triggers Notes
Cursors in PL/SQL
1. Definition:
- A cursor is a pointer to the context area that stores the result of a SQL query.
2. Types of Cursors:
a. Implicit Cursor:
- Automatically created by Oracle for single row queries (like SELECT INTO).
- Automatically managed.
- Example:
DECLARE
emp_name employees.name%TYPE;
BEGIN
END;
b. Explicit Cursor:
DECLARE
BEGIN
OPEN cursor_name;
CLOSE cursor_name;
END;
- Syntax:
-- statements
END LOOP;
5. Cursor Attributes:
6. Example:
DECLARE
BEGIN
DBMS: Cursors and Triggers (Detailed Notes)
END LOOP;
END;
Triggers in PL/SQL
1. Definition:
- A trigger is a stored procedure that executes automatically in response to certain events on a table/view.
2. Uses of Triggers:
- Auditing
3. Types of Triggers:
a. Based on Timing:
b. Based on Event:
DBMS: Cursors and Triggers (Detailed Notes)
- INSERT
- UPDATE
- DELETE
4. Syntax:
ON table_name
BEGIN
-- PL/SQL code
END;
5. Row-Level vs Statement-Level:
- Row-Level: Executes for each row affected (uses FOR EACH ROW).
6. Example:
BEGIN
END IF;
DBMS: Cursors and Triggers (Detailed Notes)
END;
7. Trigger Restrictions: