Created
October 19, 2014 01:16
-
-
Save leopic/385fed0c7e3a2bd735ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Ejercicio 3 | |
-- Leo Picado | |
SET SERVEROUTPUT ON; | |
SET VERIFY OFF; | |
-- Boostrapping | |
DROP TABLE EMPLEA_PRUEBA; | |
CREATE TABLE EMPLEA_PRUEBA AS ( | |
SELECT num_emp, nombre||' '||apellido as nombre_apellido, salario, num_dept, cod_puesto, jefe | |
FROM empleados | |
WHERE JEFE IS NOT NULL | |
); | |
ALTER TABLE EMPLEA_PRUEBA ADD CONSTRAINT fk_empleado_jefe FOREIGN KEY(JEFE) REFERENCES EMPLEADOS(NUM_EMP); | |
ALTER TABLE EMPLEA_PRUEBA ADD RANK varchar2(20); | |
-- End bootstrapping | |
DECLARE | |
-- variables | |
ranking EMPLEA_PRUEBA.RANK%TYPE; | |
pajar EMPLEA_PRUEBA.NOMBRE_APELLIDO%TYPE; | |
id_empleado EMPLEA_PRUEBA.NUM_EMP%TYPE; | |
contador number(3); | |
BEGIN | |
-- sentencias | |
-- Empleados con una 'w' en su nombre: | |
SELECT COUNT(*) INTO contador | |
FROM EMPLEA_PRUEBA | |
WHERE REGEXP_SUBSTR(lower(NOMBRE_APELLIDO), '\w+', 1, 1) LIKE '%w%'; | |
FOR j in 1..contador LOOP | |
-- Obteniendo el ID de cada empleado | |
SELECT NUM_EMP INTO id_empleado | |
FROM EMPLEA_PRUEBA | |
WHERE REGEXP_SUBSTR(lower(NOMBRE_APELLIDO), '\w+', 1, 1) LIKE '%w%' | |
AND ROWNUM <= contador OFFSET j ROWS; | |
--AND RANK IS NULL; | |
-- Obteniendo el nombre/apellido/puesto | |
SELECT lower(NOMBRE_APELLIDO||COD_PUESTO) INTO pajar | |
FROM EMPLEA_PRUEBA | |
WHERE NUM_EMP = id_empleado; | |
-- buscando las vocales | |
FOR i IN 1..length(pajar) LOOP | |
IF substr(pajar, i, 1) IN('a', 'e', 'i', 'o', 'u') THEN | |
ranking := ranking||'*'; | |
END IF; | |
END LOOP; | |
-- actualizando la tabla | |
UPDATE EMPLEA_PRUEBA | |
SET RANK = ranking | |
WHERE NUM_EMP = id_empleado; | |
END LOOP; | |
DBMS_OUTPUT.put_line('Se cambiaron un total de: '||SQL%ROWCOUNT||' empleados.'); | |
END; | |
/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment