drop table EXPLOTADO; create table EXPLOTADO ( DNI varchar(15) PRIMARY KEY, antiguedad SMALLINT NOT NULL, puesto varchar(50) DEFAULT ('PRINGAO'), sueldo float not null check (sueldo>0) ); insert into EXPLOTADO (DNI, antiguedad, sueldo) values ('44444444X', 5, 15000.0); insert into EXPLOTADO (DNI, antiguedad, sueldo) values ('54545454X', 2, 12000.0); insert into EXPLOTADO (DNI, antiguedad, sueldo) values ('44111111X', 1, 10000.0); insert into EXPLOTADO (DNI, antiguedad, sueldo) values ('55555555X', 0, 9000.0); insert into EXPLOTADO (DNI, antiguedad, sueldo) values ('77777777X', 0, 9000.0); insert into EXPLOTADO values ('33333333X', 3, 'JEFECILLO', 20000.0); select * from EXPLOTADO; /* DNI ANTIGUEDAD PUESTO SUELDO --------------- ---------- -------------------------------------------------- --------- 44444444X 5 PRINGAO 15000 54545454X 2 PRINGAO 12000 44111111X 1 PRINGAO 10000 55555555X 0 PRINGAO 9000 77777777X 0 PRINGAO 9000 33333333X 3 JEFECILLO 20000 6 rows selected. */ /* Procedimiento almacenado para modificar el sueldo a todos los "explotados" de una determinada categoria o puesto, modificando su sueldo en un tanto por ciento dado, siempre y cuando su antiguedad sea distinta de 0. Dos parametros de entrada, xPuesto y porcentaje, para especificar el puesto y porcentaje a usar. */ drop procedure MODIFICARSUELDO; create or replace procedure MODIFICARSUELDO ( xPuesto IN EXPLOTADO.puesto%type, porcentaje IN float) AS CURSOR elCurrante is select sueldo, antiguedad from EXPLOTADO where puesto=xPuesto for update of sueldo; suSueldo EXPLOTADO.sueldo%type; suAntiguedad EXPLOTADO.antiguedad%type; begin OPEN elCurrante; LOOP FETCH elCurrante into suSueldo,suAntiguedad; EXIT WHEN elCurrante%NOTFOUND; if suAntiguedad<>0 then update EXPLOTADO set Sueldo= suSueldo*((100+porcentaje)/100) where current of elCurrante; end if; END LOOP; CLOSE elCurrante; commit; END; / /* Si da aviso de que ha habido errores de compilacion, para verlos se debe teclear: show errors */ execute MODIFICARSUELDO ('PRINGAO', 3); /* SQL> select * from EXPLOTADO; DNI ANTIGUEDAD PUESTO SUELDO --------------- ---------- -------------------------------------------------- --------- 33333333X 3 JEFECILLO 20000 44444444X 5 PRINGAO 15450 54545454X 2 PRINGAO 12360 44111111X 1 PRINGAO 10300 55555555X 0 PRINGAO 9000 77777777X ,5 PRINGAO 9000 6 rows selected. SQL> */ /* Incrementar el sueldo un 2% a todos aquellos que no tengan antiguedad 0 y contar cuantos cambios se han hecho.... Bloque PL/SQL Anonimo. */ variable contador number; DECLARE CURSOR elCurrante is select sueldo, antiguedad from EXPLOTADO for update of sueldo; suSueldo EXPLOTADO.sueldo%type; suAntiguedad EXPLOTADO.antiguedad%type; begin :contador:=0; OPEN elCurrante; LOOP FETCH elCurrante into suSueldo,suAntiguedad; EXIT WHEN elCurrante%NOTFOUND; if suAntiguedad<>0 then update EXPLOTADO set Sueldo= suSueldo*(1.02) where current of elCurrante; :contador:= :contador +1; end if; END LOOP; CLOSE elCurrante; commit; END; / print contador;