Session Notes - Cursor is a memory area in which a SQL Query is processed and results are cached. Explicit/Implicit Cursors Steps - DECLARE, OPEN, FETCH UNTIL ALL ROWS ARE FETCHED AND THEN CLOSE. Four attributes - ISOPEN, NOTFOUND, FOUND, ROWCOUNT CURSOR FOR LOOPS DECLARE USING A FOR LOOP - YOU CAN OPEN, FETCH AND CLOSE (UNTIL END LOOP). USAGE OF FOR UPDATE CLAUSE CURSOR WITH PARAMETER CURSOR C1 (A1 VARCHAR, A2 VARCHAR) IS SELECT * FROM EMP WHERE ENAME LIKE A1 OR DNAME LIKE A2; BEGIN OPEN C1('BOB', 'ACCOUNTING); ... CLOSE C1; OPEN C1('SALLY', 'HR); ... CLOSE C1; END; Doing a select for update allows selection of data rows --> locked for update. Slow down the overall system. When updating exiting values in row --> useful. CURSOR c1 is select empno, ename, deptno from emp where sal > 2000 for update of dept nowait; Open --> Fetch rows in a loop - Point to current cursor --> WHERE current of c1; <-- explicit reference to rowid. BEGIN FOR emp_rec in c1 loop if emp_rec dept in (10,20) then update emp set deptno = 40 where current of c1; end if; end loop; END; / When a cursor is created with a subquery - explicit reference is given only to the outer cursor and not the internal cursor. Working with Exceptions: Block of code -- Problem occurs in code. --> Exception is thrown - ctrl of code block in send to Exception Block (Exception can be either be managed or reset). Between Begin and End clause exception can occur. Two type of exceptions can occur Oracle error - system errors. Custom exception - for application - user-defined. Pre-defined exceptions are implicitly raised. (20) Non Pre-defined exceptions User-defined exceptions are explicily raised. EXCEPTION WHEN exception1 then statements .. when exception2 then when others then end; / NO DATA FOUND TOO_MANY_ROWS non pre-defined exception declare myexception EXCEPTION; PRAGMA_EXCEPTION_INIT(myexception, -1133); begin .... exception when myexception then dbms_output.put_line('error'); end; / user-defined exception; declare myexception EXCEPTION; begin ... if sql%notfound then raise myexception; end if exception when myexception then dbms_output.put_line('error'); end; / raise_application_error(-222222, 'error message'); --used in exception block or begin block.