miércoles, 10 de octubre de 2012

Buscar bloqueos en BD oracle

Como saber si tiene alguna query  que este bloquenado la BD? aqui esta la forma de saberlo.

select object_name, session_id,oracle_username, a.* from v$locked_object a, dba_objects b where a.object_id = b.object_id

jueves, 23 de agosto de 2012

Opciones de Cascada en Hibernate

Algo importante al utilizar las cascadas de hibernate en los hbm


  • none - do not do any cascades, let the users handles them by themselves. 
  • save-update - when the object is saved/updated, check the assoications and save/update any object that require it (including save/update the assoications in many-to-many scenario). 
  • delete - when the object is deleted, delete all the objects in the assoication. 
  • delete-orphan - when the object is deleted, delete all the objects in the assoication. In addition to that, when an object is removed from the assoication and not assoicated with another object (orphaned), also delete it. 
  • all - when an object is save/update/delete, check the assoications and save/update/delete all the objects found. 
  • all-delete-orphan - when an object is save/update/delete, check the assoications and save/update/delete all the objects found. In additional to that, when an object is removed from the assoication and not assoicated with another object (orphaned), also delete it.

miércoles, 18 de abril de 2012

Crear Procedures en Oracle

Como crear un procedimiento que realice un update en BD oracle?

Se crea un procedure con nombre NOMBRE_PROCEDURE que recibe 3 parametros de entrada y retorna 2 parametros de salida.

- variableUno: lista de ids que se les debe hacer el update
- variableDos: valor que se debe setear en algun campo a actualizar
- variableTres: alguna condicion adicional que debe cumplir
- salidaUno: String que recoge todo lo que se actualizó
- salidaDos: Entero que retorna un codigo que permite comprobar que todo fue bien.


CREATE OR REPLACE PROCEDURE NOMBRE_PROCEDURE(
variableUno IN VARCHAR2,
variableDos IN VARCHAR2,
variableTres IN NUMBER,
salidaUno OUT NUMBER,
salidaDos OUT VARCHAR2
)
IS
TYPE ref1 IS REF CURSOR;
listaIds ref1;
indiceRecorrer NUMBER;

BEGIN
-- variableUno es un string separado por | donde se define una lista de ids ('1','2','3',...'n')
OPEN listaIds FOR SELECT t.* FROM TABLE(FN_SPLIT(variableUno,'|')) t;

LOOP
FETCH listaIds into indiceRecorrer;
EXIT WHEN listaIds%NOTFOUND;

--realizamos alguna accion
UPDATE TABLA_ACTUALIZAR SET ALGUN_CAMPO_ACTUALIZAR = variableDos WHERE ID_ACTUALIZAR = indiceRecorrer AND ALGUNA_COLUMNA_CONDICION = variableTres;

--recogo los ids actualizados (indiceRecorrer)
salidaUno := salidaUno || to_char(indiceRecorrer) || ',';

END LOOP;
salidaDos := 0; -- fuera del procedure se comprueba si salidaDos es == 0 entonces todo ha ido bien, sino ha sucedido algun error.

COMMIT;

EXCEPTION
WHEN OTHERS THEN
salidaDos := -1000;
DBMS_OUTPUT.PUT_LINE('SE PRODUJO UN ERROR EN EL PROCESO, SE REALIZARA UN ROLLBACK.' || SQLCODE || SQLERRM);
ROLLBACK;
RAISE;

END NOMBRE_PROCEDURE;
/