Вы находитесь на странице: 1из 3

--pragma exception (without cursor hence commented) declare empno emp.emp_no%type; ebasic emp.basic%type; desgn emp.desig%type; enm emp.

emp_name%type; --egross emp.gross%type; -cursor cur_basic is select basic from emp where desig='lect'; NO_DATA_FOUND exception; Resource_Busy exception; PRAGMA exception_init(Resource_Busy,-00054); begin empno:=&empno; -------open cur_basic; loop fetch cur_basic into basic; exit when cur_basic%NOTFOUND; if basic<15000 then raise NO_DATA_FOUND; end if;

select basic,emp_name into ebasic,enm from emp where desig='lect' and emp_name='Anil' for update nowait; update emp set basic=ebasic+500; -end loop; exception when Resource_Busy then dbms_output.put_line('row is busy'); when NO_DATA_FOUND then dbms_output.put_line('no data found'); end; . / on 1 terminal SQL> select * from emp; EMP_NO EMP_NAME BASIC COMM ---------- ---------- ----------1 Anil 15000 200 2 madhavi 15000 340 3 madhavi 15000 340 on 2nd terminal SQL> / Enter value for empno: 1 old 13: empno:=&empno; new 13: empno:=1; row is busy DESIG GR MGRNO DEPTNO

---------- -- ---------- ---------- -------lect prof lect A b b 40 80 80

PL/SQL procedure successfully completed.

SQL> select * from emp; EMP_NO COMM ----------1 200 2 340 3 340 EMP_NAME BASIC DESIG GR MGRNO DEPTNO

---------- ---------- ---------- -- ---------- ---------- -------Anil madhavi madhavi 14000 lect 23000 prof 23000 lect A b b 40 80 80

--pragma exception(with cursor ) declare empno emp.emp_no%type; ebasic emp.basic%type; desgn emp.desig%type; enm emp.emp_name%type; -egross emp.gross%type; cursor cur_basic is select basic from emp where desig='lect'; NO_DATA_FOUND exception; Resource_Busy exception; PRAGMA exception_init(Resource_Busy,-00054);

begin open cur_basic; loop fetch cur_basic into ebasic; exit when cur_basic%NOTFOUND; if ebasic<16000 then select emp_name,basic into enm,ebasic from emp where desig='lect' and emp_name='Anil' for update nowait; update emp set basic=ebasic+500; else raise NO_DATA_FOUND; end if; end loop; exception when Resource_Busy then dbms_output.put_line('row is busy'); when NO_DATA_FOUND then dbms_output.put_line('no data found'); end; . / O/p of one terminal SQL> /

row is busy PL/SQL procedure successfully completed. SQL> select * from emp; EMP_NO COMM ----------1 200 2 340 3 340 EMP_NAME BASIC DESIG GR MGRNO DEPTNO

---------- ---------- ---------- -- ---------- ---------- -------Anil madhavi madhavi 14000 lect 23000 prof 23000 lect A b b 40 80 80

SQL> select * from emp; EMP_NO COM ---------1 20 2 34 3 34 EMP_NAME BASIC DESIG GR MGRNO DEPTNO

---------- ---------- ---------- -- ---------- ---------- -------Anil madhavi madhavi 16000 lect 16000 prof 16000 lect A b b 40 80 80

PL/SQL procedure successfully completed.

Вам также может понравиться