-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths-06-ilap-cah-s1-sucursal-venta-trigger.sql
107 lines (102 loc) · 3.81 KB
/
s-06-ilap-cah-s1-sucursal-venta-trigger.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
--@Autor: Carlos A. Hernández A. & Marco A. Moreno Guerra
--@Fecha creación: 16/05/2020
--@Descripción: Definición del trigger para operaciones DML para SUCURSAL_VENTA
-- en CAHABDD_S1
create or replace trigger t_dml_sucursal_venta_cah_s1
instead of insert or update or delete on SUCURSAL_VENTA
declare
v_count number;
begin
case
when inserting then
select count(*)
into v_count
from SUCURSAL_F1
where sucursal_id = :new.sucursal_id;
-- Inserción local (en CAHABDD_S1)
if v_count > 0 then
insert into SUCURSAL_VENTA_F1(sucursal_id, hora_apertura, hora_cierre)
values (:new.sucursal_id, :new.hora_apertura, :new.hora_cierre);
else
select count(*)
into v_count
from SUCURSAL_F2
where sucursal_id = :new.sucursal_id;
-- Inserción remota en CAHABDD_S2
if v_count > 0 then
insert into SUCURSAL_VENTA_F2(sucursal_id, hora_apertura, hora_cierre)
values (:new.sucursal_id, :new.hora_apertura, :new.hora_cierre);
else
select count(*)
into v_count
from SUCURSAL_F3
where sucursal_id = :new.sucursal_id;
-- Inserción remota en MAMGBD_S1
if v_count > 0 then
insert into SUCURSAL_VENTA_F3(sucursal_id, hora_apertura, hora_cierre)
values (:new.sucursal_id, :new.hora_apertura, :new.hora_cierre);
else
select count(*)
into v_count
from SUCURSAL_F4
where sucursal_id = :new.sucursal_id;
-- Inserción remota en MAMGBD_S2
if v_count > 0 then
insert into SUCURSAL_VENTA_F4(sucursal_id, hora_apertura, hora_cierre)
values (:new.sucursal_id, :new.hora_apertura, :new.hora_cierre);
else
raise_application_error(-20020, 'Error de integridad para el campo SUCURSAL_ID: '
|| :new.sucursal_id || ' No se encontró el registro padre en los fragmentos');
end if;
end if;
end if;
end if;
when deleting then
select count(*)
into v_count
from SUCURSAL_F1
where sucursal_id = :old.sucursal_id;
-- Delete local (en CAHABDD_S1)
if v_count > 0 then
delete from SUCURSAL_VENTA_F1
where sucursal_id = :old.sucursal_id;
else
select count(*)
into v_count
from SUCURSAL_F2
where sucursal_id = :old.sucursal_id;
-- Delete remoto en CAHABDD_S2
if v_count > 0 then
delete from SUCURSAL_VENTA_F2
where sucursal_id = :old.sucursal_id;
else
select count(*)
into v_count
from SUCURSAL_F3
where sucursal_id = :old.sucursal_id;
-- Delete remoto en MAMGBD_S1
if v_count > 0 then
delete from SUCURSAL_VENTA_F3
where sucursal_id = :old.sucursal_id;
else
select count(*)
into v_count
from SUCURSAL_F4
where sucursal_id = :old.sucursal_id;
-- Delete remoto en MAMGBD_S2
if v_count > 0 then
delete from SUCURSAL_VENTA_F4
where sucursal_id = :old.sucursal_id;
else
raise_application_error(-20020, 'Error de integridad para el campo SUCURSAL_ID: '
|| :old.sucursal_id || ' No se encontró el registro padre en los fragmentos');
end if;
end if;
end if;
end if;
when updating then
raise_application_error(-20030, 'Las operaciones UPDATE no tienen soporte aun.');
end case;
end;
/
show errors