Created
November 18, 2021 09:55
-
-
Save gonzaleztroyano/1ad5bdb04031ec8f7b679471d527c546 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
DELIMITER ## | |
DROP PROCEDURE IF EXISTS act_jefe## | |
CREATE PROCEDURE act_jefe(IN dir_anti VARCHAR(9), | |
IN dir_nuevo VARCHAR(9)) | |
BEGIN | |
DECLARE num_filas INT DEFAULT 0; | |
DECLARE cuenta_bucle INT DEFAULT 0; | |
DECLARE local_dni VARCHAR(9) DEFAULT 'PEPE'; | |
DECLARE local_jefe VARCHAR(9) DEFAULT 'PEPE'; | |
DECLARE cursordirectores CURSOR FOR | |
SELECT DNI, DNIJefe | |
FROM directores | |
WHERE DNIJefe = (dir_anti OR dir_nuevo); | |
SELECT FOUND_ROWS( ) INTO num_filas; | |
OPEN cursordirectores; | |
WHILE cuenta_bucle < num_filas DO | |
BEGIN | |
FETCH cursordirectores INTO local_dni, local_jefe; | |
IF local_jefe = dir_anti THEN | |
UPDATE directores | |
SET DNIJefe = dir_nuevo | |
WHERE DNI = local_dni; | |
END IF; | |
IF local_jefe = dir_nuevo THEN | |
UPDATE directores | |
SET DNIJefe = dir_anti | |
WHERE DNI = local_dni; | |
END IF; | |
SET cuenta_bucle = cuenta_bucle + 1; | |
END; | |
END WHILE; | |
-- Cerrar cursos -- | |
CLOSE cursordirectores; | |
END## | |
CALL act_jefe('D1','D3'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment