This procedure updates a table where I keep track of a (very-basic) historical work done. The problem is that I can’t modify it or compile it anymore. I don’t know if I’m making a mistake in the procedure and an infinite-loop is going on. My DBA has checked the procedure and everything’s seems right, but I still can’t change it, use it.
My bet is that when I’m trying to catch the exception and I use the EXCEPTION WHEN OTHERS THEN NULL the loop gets stuck.
Any advise?
Cheers
create or replace
PROCEDURE DOACTUALIZARHISTORIALEM
(
QUSUARIO IN VARCHAR2
, QARCHIVO IN VARCHAR2
, QANIOFISCAL IN VARCHAR2
, QFECHAPROCESAMIENTO IN DATE
) AS
cursorEstatus SYS_REFCURSOR;
sqlQueryA VARCHAR2(200);
sqlQueryB VARCHAR2(200);
idArchivo INTEGER;
idPrograma VARCHAR2(10);
idComponente VARCHAR2(10);
sumaSolicitado DECIMAL;
sumaAprobado DECIMAL;
sumaPagado DECIMAL;
BEGIN
idArchivo := getidarchivo(qarchivo,getidusuario(qusuario),qaniofiscal);
sqlQueryA := 'SELECT programa, componente'||
' FROM '||qusuario||
' WHERE id_archivo = :1';
OPEN cursorEstatus FOR sqlQueryA USING idArchivo;
LOOP
FETCH cursorEstatus INTO idPrograma, idComponente;
EXIT WHEN cursorEstatus%NOTFOUND;
BEGIN
sqlQueryB := 'SELECT sum(monto_federal) '||
' FROM '||qusuario||
' WHERE programa = :1'||
' AND componente = :2'||
' AND estatus_monto = 1'||
' AND status = 1';
EXECUTE IMMEDIATE sqlQueryB
INTO sumaSolicitado
USING idPrograma, idComponente;
INSERT INTO src_historialem VALUES (idArchivo,
qfechaprocesamiento,
idPrograma,
idComponente,
1,
sumaSolicitado);
COMMIT;
EXCEPTION
WHEN OTHERS THEN NULL;
END;
BEGIN
sqlQueryB := 'SELECT sum(monto_federal) '||
' FROM '||qusuario||
' WHERE programa = :1'||
' AND componente = :2'||
' AND estatus_monto = 2'||
' AND status = 1';
EXECUTE IMMEDIATE sqlQueryB
INTO sumaAprobado
USING idPrograma, idComponente;
INSERT INTO src_historialem VALUES (idArchivo,
qfechaprocesamiento,
idPrograma,
idComponente,
2,
sumaSolicitado);
COMMIT;
EXCEPTION
WHEN OTHERS THEN NULL;
END;
BEGIN
sqlQueryB := 'SELECT sum(monto_federal) '||
' FROM '||qusuario||
' WHERE programa = :1'||
' AND componente = :2'||
' AND estatus_monto = 3'||
' AND status = 1';
EXECUTE IMMEDIATE sqlQueryB
INTO sumaPagado
USING idPrograma, idComponente;
INSERT INTO src_historialem VALUES (idArchivo,
qfechaprocesamiento,
idPrograma,
idComponente,
3,
sumaSolicitado);
COMMIT;
EXCEPTION
WHEN OTHERS THEN NULL;
END;
END LOOP;
CLOSE cursorEstatus;
END DOACTUALIZARHISTORIALEM;
1) Open a SQL*Plus session (session A). Get that session’s
SIDandSERIAL#. Write those numbers down.2) Open a second SQL*Plus session (session B) connecting to the same database as A.
3) In session A, try to compile the code
4) While that is running, in session B, run the query
That will show you the
SIDof the session that holds the lock on the procedure. Alternately,dba_waitersshould have similar information.5) Once you’ve determined what session holds the lock, you can ask the DBA to kill the session.