Cursor cursor is a private sql work area. Every sql statement executed by oracle server has an individual cursor associated with it. Cursor are two types 1.Implicit cursor 2.Explicit cursor Implicit cursor: Implicit cursors are declared by pl/sql implicitly at the time of DML statement and select statement in pl/sql including queries that returns single row. cursor have four attributes 1. SQL%ROWCOUNT 2. SQL%ISOPEN 3. SQL%NOTFOUND 4. SQL%FOUND SQL%ROWCOUNT-Basically it returns number. means number of rows affected by present sql statement. SQL%ISOPEN-Always evalutes false because implicit cursor automatically closed after execution of sql statement. SQL%FOUND-Always evalutes true because one or more rows are affected by recent sql statement SQL%NOTFOUND-Always evalutes true when no rows are affected by present sql statement.
example of explicit cursor DECLARE v_empno employees.employee_id%TYPE; v_name employees.last_name%TYPE; CURSOR emp_cur IS SELECT employee_id,last_name FROM employees BEGIN OPEN emp_cur; LOOP FETCH emp_cur INTO v_empno,v_name ; EXIT WHEN emp_cur%ROWCOUNT>10 OR emp_cur%NOTFOUND;
Trigger:-Trigger is pl/sql block or procedure that is associated with table,view,schema and database. Execute immidiately when particular event take place. there are two types of trigger 1.Application trigger:fires automatically when event occurs with particular application. 2.Database trigger:Fires when data such as DML oparation occured at that time. DML triggers are two types 1.Statementlevel trigger 2.Rowlevel trigger
statement level trigger-statement level trigger means trigger body execute once for the triggering event.this is default.A statement level trigger fire once even no rows are affected at all. Row level- Trigger body execute once for each row affected by triggering event.if no rows are affected in that case trigger body not executed. trigger example CREATE OR REPLACE TRIGGER secure_emp BEFORE INSERT ON employees BEGIN TO_CHAR(SYSDATE,'DY')IN('SUN','SAT') OR TO_CHAR((SYSDATE,'HH24:MI')NOT BETWEEN '08:00' AND '18:00')THEN RAISE_APPLICATION_ERROR(-20253,'u may insert employee information at business hrs'); END;
Trigger is a stored procedure that invokes automatically when the event occurs. We can write 12 types of triggers on table and 15 types of triggers on views. Cursor pointer or handler to the context area . 2 types of cursors are there implicit and explicit cursors.
Trigger ------- Trigger is a pl/sql block which is executed whenever any dml statement(insert,update,delete)issued against the table.
Cursor ------ Cursor is a memory area in which all the statement are executed and store the result. cursor is 2 types namely implicit cursor and explicit cursor. Implicit cursor fetches only one row (normal select into statement) where as Explicit cursor is fetching more than one row and process one by one. In explicit cursor user have to explicitily name the cursor.
Function -------- Function is a named pl/sql block which is stored in database. We can invoke by calling the name of the function whenever we need. Function is always return a value. Source: CoolInterview.com