My stored procedure looks like follows:
sqlQuery := 'DROP INDEX idArchivoIndex';
EXECUTE IMMEDIATE sqlQuery;
EXCEPTION --En caso de que no exista el índice capturamos la excepcion
WHEN index_not_exists THEN NULL; --y la ignoramos
sqlQuery := 'CREATE INDEX idArchivoIndex'||
' ON '||qusuario||' (id_archivo)';
EXECUTE IMMEDIATE sqlQuery;
doresetvalidacion(qusuario, idarchivo);
IF (tipoDependencia = 'PEC') THEN
dovalidapec(qusuario,qaniofiscal,idarchivo,imprimirMensajes);
COMMIT;
ELSIF (tipoDependencia = 'SAGARPA') THEN
dovalidacionpec(qusuario,qaniofiscal,idarchivo,imprimirMensajes);
COMMIT;
END IF;
If the exception is not raised the procedure just drops the index but no index is recreated ! I thought that this part of the code
EXCEPTION
WHEN index_not_exists THEN NULL;
Handled the error and then continue with the code below it. Now that I see the results what's after the EXCEPTION is executed if and only if the exception was raised.
What I want is to simplify my code, I don't want to copy-paste the same block of code before the EXCEPTION clause just to make it work as I expect. Is there a way to achieve it? Maybe with a nested BEGIN ... END block? Or will I have to make a separate procedure to reuse code?
Cheers.
UPDATE
create or replace
PROCEDURE DOVALIDAINFORMACION
(
QARCHIVO IN VARCHAR2
, QUSUARIO IN VARCHAR2
, QANIOFISCAL IN VARCHAR2
) AS
imprimirMensajes CHAR;
tipoDependencia VARCHAR2(25);
idArchivo NUMBER;
sqlQuery VARCHAR2(100);
index_not_exists EXCEPTION;
PRAGMA EXCEPTION_INIT(index_not_exists, -1418);
BEGIN
sqlQuery := 'DROP INDEX idArchivoIndex';
EXECUTE IMMEDIATE sqlQuery;
----------------------
EXCEPTION --En caso de que no exista el índice capturamos la excepcion
WHEN index_not_exists THEN --y la ignoramos
NULL;
END;
----------------------
sqlQuery := 'CREATE INDEX idArchivoIndex'||
' ON '||qusuario||' (id_archivo)';
EXECUTE IMMEDIATE sqlQuery;
doresetvalidacion(qusuario, idarchivo);
IF (tipoDependencia = 'PEC') THEN
dovalidapec(qusuario,qaniofiscal,idarchivo,imprimirMensajes);
COMMIT;
ELSIF (tipoDependencia = 'SAGARPA') THEN
dovalidacionpec(qusuario,qaniofiscal,idarchivo,imprimirMensajes);
COMMIT;
END IF;
END DOVALIDAINFORMACION;
But can't compile the procedure.
Error(32,3): PLS-00103: Se ha encontrado el símbolo "SQLQUERY"
Error(33,48): PLS-00103: Se ha encontrado el símbolo ";" cuando se esperaba uno de los siguientes: ) , * & = - + < / > at in is mod remainder not rem <an exponent (**)> <> or != or ~= >= <= <> and or like LIKE2_ LIKE4_ LIKEC_ between || member SUBMULTISET_