Created
March 15, 2017 18:32
-
-
Save primogf/383830dc50f0499f88141cdfb7a6e56e 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
CREATE DEFINER=`root`@`localhost` PROCEDURE `new_procedure`() | |
BEGIN | |
declare var_id_usuario int; | |
set var_id_usuario = 108; | |
BLOCK1: begin | |
DECLARE fim INT DEFAULT false; | |
declare var_id_documento int; | |
declare cursor1 cursor for | |
select | |
id_documento_tipo | |
from | |
DocumentTypeMainData | |
where | |
stat <> 0 and niv_1 = 1 and niv_2 = 1 and niv_3 = 1 and (niv_4 between 7 and 10); | |
DECLARE CONTINUE handler FOR NOT found SET fim = TRUE; | |
open cursor1; | |
LOOP1: loop | |
fetch cursor1 | |
into var_id_documento; | |
if fim then | |
close cursor1; | |
leave LOOP1; | |
end if; | |
BLOCK2: begin | |
declare var_id_empresa int; | |
DECLARE fim2 INT DEFAULT false; | |
declare cursor2 cursor for | |
select id_empresa from UserEnabledEnvironment where id_usuario = var_id_usuario; | |
DECLARE CONTINUE handler FOR NOT found SET fim2 = TRUE; | |
open cursor2; | |
LOOP2: loop | |
fetch cursor2 | |
into var_id_empresa; | |
insert into DocumentTypeResponsibleUser (id_documento_tipo,id_empresa,id_usuario,stat) | |
value (var_id_documento,var_id_empresa,var_id_usuario,1) ; | |
if fim2 then | |
close cursor2; | |
leave LOOP2; | |
end if; | |
end loop LOOP2; | |
end BLOCK2; | |
end loop LOOP1; | |
end BLOCK1; | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment