I don't know if thats right but for some reason my stored procedure is not rolling back after an exception occurs. So my insert statement is commited even when i get an exception
Did i forgot something?
PROCEDURE SP_USUARIO_INSERT
(
pUSU_IDUSUARIO IN OUT ENG.USU_USUARIO.USU_IDUSUARIO%TYPE,
pUSU_CDUSUARIO IN ENG.USU_USUARIO.USU_CDUSUARIO%TYPE,
pPES_IDPESSOA IN ENG.USU_USUARIO.PES_IDPESSOA%TYPE,
pUSU_DLSENHA IN ENG.USU_USUARIO.USU_CDUSUARIO%TYPE,
pUSU_DLOBSERVACAO IN ENG.USU_USUARIO.USU_DLOBSERVACAO%TYPE,
pUSU_NUIP IN ENG.USU_USUARIO.USU_NUIP%TYPE,
pUSU_DTCADASTRO IN ENG.USU_USUARIO.USU_DTCADASTRO%TYPE,
pUSU_DTDESATIVACAO IN ENG.USU_USUARIO.USU_DTDESATIVACAO%TYPE,
pUSU_DTULTIMOACESSO IN ENG.USU_USUARIO.USU_DTULTIMOACESSO%TYPE,
pUSU_DLMAQUINA IN ENG.USU_USUARIO.USU_DLMAQUINA%TYPE,
pUSU_STNOVO IN ENG.USU_USUARIO.USU_STNOVO%TYPE,
pUSU_STATIVO IN ENG.USU_USUARIO.USU_STATIVO%TYPE
)
IS
sCreateUser Varchar(200);
bUsuarioExiste Number;
eUsuarioExiste Exception;
BEGIN
SELECT
COUNT(usu_cdusuario)
INTO bUsuarioExiste
FROM ENG.USU_USUARIO
WHERE USU_CDUSUARIO = pUSU_CDUSUARIO;
IF(bUsuarioExiste > 0) THEN
RAISE eUsuarioExiste;
END IF;
SELECT usu_seq.nextval INTO pUSU_IDUSUARIO FROM DUAL;
INSERT INTO ENG.USU_USUARIO
(
USU_IDUSUARIO,
USU_CDUSUARIO,
PES_IDPESSOA,
USU_DLOBSERVACAO,
USU_NUIP,
USU_DTCADASTRO,
USU_DTDESATIVACAO,
USU_DTULTIMOACESSO,
USU_DLMAQUINA,
USU_STNOVO,
USU_STATIVO
)
VALUES
(
pUSU_IDUSUARIO,
pUSU_CDUSUARIO,
pPES_IDPESSOA,
pUSU_DLOBSERVACAO,
pUSU_NUIP,
sysdate,
pUSU_DTDESATIVACAO,
pUSU_DTULTIMOACESSO,
pUSU_DLMAQUINA,
pUSU_STNOVO,
pUSU_STATIVO
) ;
sCreateUser := 'CREATE USER ' || pUSU_CDUSUARIO || ' IDENTIFIED BY ' || pUSU_DLSENHA;
EXECUTE IMMEDIATE sCreateUser;
EXECUTE IMMEDIATE 'GRANT ENG_GERAL TO ' || pUSU_CDUSUARIO;
COMMIT;
EXCEPTION
WHEN eUsuarioExiste THEN
RAISE_APPLICATION_ERROR (-20001, 'Usuário já existe ou possui nome inválido.');
ROLLBACK;
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR (-20001, SQLCODE || ': ' || SQLERRM);
ROLLBACK;
END SP_USUARIO_INSERT;