TRIGGER ORACLE
--tables
CREATE TABLE CLIENTE
(
CODCLIENTE NUMBER PRIMARY KEY,
RAZONSOCIAL VARCHAR2(50),
DIRECCION VARCHAR2(50),
RUC CHAR(11)
);
INSERT INTO CLIENTE VALUES(1,'Empresa1','Jr. Amazonas #2312','12045236014');
INSERT INTO CLIENTE VALUES(2,'Empresa2','Jr. Amazonas #2313','12045236011');
INSERT INTO CLIENTE VALUES(3,'Empresa3','Jr. Amazonas #2315','12045236023');
INSERT INTO CLIENTE VALUES(4,'Empresa4','Jr. Amazonas #2315','12045236023');
INSERT INTO CLIENTE VALUES(5,'Empresa5','Jr. Amazonas #2316','22045236021');
select * from cliente;
CREATE TABLE BITCLIENTE
(
CODCLIENTE NUMBER,
RUC CHAR(11),
FECHA DATE,
HORA CHAR(10)
);
--trigger
CREATE OR REPLACE TRIGGER TR_01
AFTER INSERT ON CLIENTE
FOR EACH ROW
BEGIN
INSERT INTO BITCLIENTE(CODCLIENTE,RUC,FECHA,HORA)
VALUES(:NEW.codcliente, :NEW.ruc, TO_DATE(SYSDATE,'DD/MM/YY'), TO_CHAR(SYSDATE,'HH24:MI'));
END TR_01;
--probar trigger_tr_01
SELECT * FROM BITCLIENTE;
--by Ing. Jhonatan Abal Mejia
CREATE TABLE CLIENTE
(
CODCLIENTE NUMBER PRIMARY KEY,
RAZONSOCIAL VARCHAR2(50),
DIRECCION VARCHAR2(50),
RUC CHAR(11)
);
INSERT INTO CLIENTE VALUES(1,'Empresa1','Jr. Amazonas #2312','12045236014');
INSERT INTO CLIENTE VALUES(2,'Empresa2','Jr. Amazonas #2313','12045236011');
INSERT INTO CLIENTE VALUES(3,'Empresa3','Jr. Amazonas #2315','12045236023');
INSERT INTO CLIENTE VALUES(4,'Empresa4','Jr. Amazonas #2315','12045236023');
INSERT INTO CLIENTE VALUES(5,'Empresa5','Jr. Amazonas #2316','22045236021');
select * from cliente;
CREATE TABLE BITCLIENTE
(
CODCLIENTE NUMBER,
RUC CHAR(11),
FECHA DATE,
HORA CHAR(10)
);
--trigger
CREATE OR REPLACE TRIGGER TR_01
AFTER INSERT ON CLIENTE
FOR EACH ROW
BEGIN
INSERT INTO BITCLIENTE(CODCLIENTE,RUC,FECHA,HORA)
VALUES(:NEW.codcliente, :NEW.ruc, TO_DATE(SYSDATE,'DD/MM/YY'), TO_CHAR(SYSDATE,'HH24:MI'));
END TR_01;
--probar trigger_tr_01
SELECT * FROM BITCLIENTE;
--by Ing. Jhonatan Abal Mejia
Comentarios