martes, 21 de mayo de 2013

Triggers con inserting, updating y deleting Oracle



CREATE OR REPLACE TRIGGER TR_AUDITA
BEFORE INSERT OR DELETE OR UPDATE
ON TABLA_REGISTRO
FOR EACH ROW
DECLARE
BEGIN
IF INSERTING  THEN 
:NEW.USUARIOMOD:=USER;
:NEW.FECHAMOD:=SYSDATE;
INSERT INTO TABLA_AUDITA VALUES(USER,SYSDATE,'INGRESO EN TABLA_REGISTRO','NOMBRE '||:NEW.NOMBRE);
END IF;
IF UPDATING THEN 
:NEW.USUARIOMOD:=USER;
:NEW.FECHAMOD:=SYSDATE;
   INSERT INTO TABLA_AUDITA VALUES(USER,SYSDATE,'ACTUALIZO EN TABLA_REGISTRO' ,'NOMBRE '||:OLD.NOMBRE||'NOMBRE '||:NEW.NOMBRE);
END IF;
IF   DELETING THEN 
   INSERT INTO TABLA_AUDITA VALUES(USER,SYSDATE,'BORRO EN TABLA_REGISTRO','NOMBRE '||:OLD.NOMBRE);
END IF;

END;
/

Hay que recordar que si vamos a insertar (inserting) no ponemos :old. ya que es un nuevo registro y por ende no existe.
Para updating ponemos :new y :old, ya que si actualizamos va a ser de un registro existente y de ello se va a derivar un registro nuevo.
En el deleting solo ponemos :old debido a que vamos a eliminar un registro viejo, no va a ser un registro nuevo ovbiamente.


viernes, 10 de mayo de 2013

Llamar a un reporte desde Oracle forms


PROCEDURE nombre_procedure IS

plid paramlist;
the_param varchar2(15) := 'tmpdata';

BEGIN
plid := get_parameter_list(the_param);
/* check if 'tmpdata' exists */
IF NOT id_null(plid) THEN
destroy_parameter_list(plid);
END IF;
/* if it does destroy it */
plid := create_parameter_list(the_param);
/* create it afresh */
add_parameter(plid, 'P_PROVINCIA', TEXT_PARAMETER,To_char(:nombre_bloque.campo_bloque));
/* associate the param in the form with the param in the report */
add_Parameter(plid, 'PARAMFORM', TEXT_PARAMETER, 'YES');
/* to suppress the parameter form displaying */
run_product(REPORTS, /* product name */
'nombre_reporte.rep', /* Oracle Reports module */
SYNCHRONOUS, /* communication mode */
RUNTIME, /* execution mode */
FILESYSTEM, /* location of the Reports module */
plid, /* handle to the parameter list */
null
);
END;

En el lienzo creamos un botón, a este botón le asignamos un trigger inteligente when-button-pressed y digitamos el sigiente código:

nombre_procedure;

Listo.