forked from db-team8/AML-system
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhase4-2.trigger.sql
119 lines (106 loc) · 4.05 KB
/
Phase4-2.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
108
109
110
111
112
113
114
115
116
117
118
119
SET DEFINE OFF;
CREATE OR REPLACE PROCEDURE get_name(
CNTR_NAME VARCHAR2,
NAME_ALERT OUT VARCHAR2
)
IS
BEGIN
-- insert into name_alert
SELECT NAME INTO NAME_ALERT
FROM DNG_PERS WHERE CNTR_NAME = NAME;
EXCEPTION
WHEN NO_DATA_FOUND THEN dbms_output.put_line('Watchlist NAME과 일치하는 데이터 없음.');
END;
/
CREATE OR REPLACE PROCEDURE get_acct(
ACCOUNT_NUMBER VARCHAR2,
ACCOUNT_ALERT OUT VARCHAR2
)
IS
BEGIN
-- insert into account_alert
SELECT ACCT_NO INTO ACCOUNT_ALERT
FROM DNG_ACCT WHERE ACCOUNT_NUMBER = ACCT_NO;
EXCEPTION
WHEN NO_DATA_FOUND THEN dbms_output.put_line('Watchlist ACCOUNT와 일치하는 데이터 없음.');
END;
/
CREATE OR REPLACE TRIGGER TXN_ALERT
BEFORE INSERT ON TRANSACTION
FOR EACH ROW
DECLARE
NAME_ALERT VARCHAR2(50) := NULL;
ACCOUNT_ALERT VARCHAR2(20) := NULL;
SCORE NUMBER(3);
REASON VARCHAR2(50);
STATUS CHAR(1);
BEGIN
get_name(:NEW.CNTR_NAME, NAME_ALERT);
get_acct(:NEW.ACCOUNT_NUMBER, ACCOUNT_ALERT);
STATUS := '0'; --judging...
dbms_output.put_line('Trigger Logic ing...');
-- insert into dng_txn
IF :NEW.AMOUNT>1000000 AND NAME_ALERT IS NOT NULL AND ACCOUNT_ALERT IS NOT NULL THEN
REASON := 'Suspicious person & account & transfer too much money.';
SCORE := 999;
:NEW.STATUS := '0';
INSERT INTO DNG_TXN (TXN_ID, SCORE, REASON, STATUS) VALUES
(:NEW.TXN_ID, SCORE, REASON, STATUS);
dbms_output.put_line('New Alert of Transaction occured.: '||:New.TXN_ID);
dbms_output.put_line('REASON: '||REASON);
ELSIF :NEW.AMOUNT>1000000 AND NAME_ALERT IS NOT NULL THEN
REASON := 'Suspicious person & transfer too much money.';
SCORE := 750;
:NEW.STATUS := '0';
INSERT INTO DNG_TXN (TXN_ID, SCORE, REASON, STATUS) VALUES
(:NEW.TXN_ID, SCORE, REASON, STATUS);
dbms_output.put_line('New Alert of Transaction occured.: '||:New.TXN_ID);
dbms_output.put_line('REASON: '||REASON);
ELSIF :NEW.AMOUNT>1000000 AND ACCOUNT_ALERT IS NOT NULL THEN
REASON := 'Suspicious account & transfer too much money.';
SCORE := 750;
:NEW.STATUS := '0';
INSERT INTO DNG_TXN VALUES (:NEW.TXN_ID, SCORE, REASON, STATUS);
dbms_output.put_line('New Alert of Transaction occured.: '||:New.TXN_ID);
dbms_output.put_line('REASON: '||REASON);
ELSIF NAME_ALERT IS NOT NULL AND ACCOUNT_ALERT IS NOT NULL THEN
REASON := 'Suspicious person & account.';
SCORE := 800;
:NEW.STATUS := '0';
INSERT INTO DNG_TXN (TXN_ID, SCORE, REASON, STATUS) VALUES
(:NEW.TXN_ID, SCORE, REASON, STATUS);
dbms_output.put_line('New Alert of Transaction occured.: '||:New.TXN_ID);
dbms_output.put_line('REASON: '||REASON);
ELSIF NAME_ALERT IS NOT NULL THEN
REASON := 'Suspicious person.';
SCORE := 600;
:NEW.STATUS := '0';
INSERT INTO DNG_TXN (TXN_ID, SCORE, REASON, STATUS) VALUES
(:NEW.TXN_ID, SCORE, REASON, STATUS);
dbms_output.put_line('New Alert of Transaction occured.: '||:New.TXN_ID);
dbms_output.put_line('REASON: '||REASON);
ELSIF ACCOUNT_ALERT IS NOT NULL THEN
REASON := 'Suspicious account.';
SCORE := 600;
:NEW.STATUS := '0';
INSERT INTO DNG_TXN (TXN_ID, SCORE, REASON, STATUS) VALUES
(:NEW.TXN_ID, SCORE, REASON, STATUS);
dbms_output.put_line('New Alert of Transaction occured.: '||:New.TXN_ID);
dbms_output.put_line('REASON: '||REASON);
ELSIF :NEW.AMOUNT>1000000 THEN
REASON := 'transfer too much money.';
SCORE := 500;
:NEW.STATUS := '0';
INSERT INTO DNG_TXN (TXN_ID, SCORE, REASON, STATUS) VALUES
(:NEW.TXN_ID, SCORE, REASON, STATUS);
dbms_output.put_line('New Alert of Transaction occured.: '||:New.TXN_ID);
dbms_output.put_line('REASON: '||REASON);
ELSE
:NEW.STATUS := '1';
dbms_output.put_line('Transaction successd.');
END IF;
EXCEPTION
WHEN OTHERS THEN dbms_output.put_line('<<ERROR>>>');
dbms_output.put_line('에러코드 : ' || SQLCODE);
dbms_output.put_line('에러내용 : ' || SUBSTR(SQLERRM,1,100));
END TXN_ALERT;