forked from kawshikbuet17/bikroy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPL_SQL_triggers.txt
224 lines (173 loc) · 7.27 KB
/
PL_SQL_triggers.txt
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
-----password hashing------------------------------------------------------------------------
-----when inserting or updating password----
CREATE OR REPLACE TRIGGER PASSWORD_HASH
BEFORE INSERT OR UPDATE
--OF PASSWORD
ON ACCOUNT
FOR EACH ROW
DECLARE
HASHED_PASS VARCHAR2(30);
TEMP VARCHAR2(30);
BEGIN
TEMP := :NEW.PASSWORD;
SELECT ORA_HASH(TEMP) INTO HASHED_PASS FROM DUAL;
dbms_output.put_line(HASHED_PASS);
:NEW.PASSWORD := HASHED_PASS;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('NO DATA FOUND') ;
WHEN TOO_MANY_ROWS THEN
DBMS_OUTPUT.PUT_LINE('MORE THAN ONE DATA FOUND') ;
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('UNKNOWN ERROR OCCURED') ;
END;
/
-------------------------------------------------------------------------------------------------------------
--------Welcome Message from bikroy admin to user after sign up-----------------------------------------------------------
CREATE OR REPLACE TRIGGER WELCOME_MSG
AFTER INSERT
ON ACCOUNT
FOR EACH ROW
DECLARE
MSG_TO VARCHAR2(20);
BEGIN
MSG_TO := :NEW.USERNAME;
INSERT INTO chat
VALUES(CHAT_SEQUENCE.NEXTVAL, 'Dear '||MSG_TO||', Welcome to BIKROY.COM, Thank you for your subsciption to our website. Enjoy buying and selling with us. You will get notified with this thread while necessary. Have a good day!', SYSDATE, 'bikroy', MSG_TO);
dbms_output.put_line('USER IS WELCOMED');
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('NO DATA FOUND') ;
WHEN TOO_MANY_ROWS THEN
DBMS_OUTPUT.PUT_LINE('MORE THAN ONE DATA FOUND') ;
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('UNKNOWN ERROR OCCURED') ;
END;
/
----------------------------------------------------------------------------------------------------------------------------
---------------Submission of Prod Ad notification msg (before confirmation)---------------------------------------------------------------
CREATE OR REPLACE TRIGGER PRODUCT_AD_SUBMISSION_MSG
AFTER INSERT
ON PRODUCT
FOR EACH ROW
DECLARE
MSG_TO VARCHAR2(20);
AD_ID VARCHAR2(20);
PROD_ID VARCHAR2(20);
PROD_NAME VARCHAR2(200);
MSG_CONT VARCHAR2(2000);
BEGIN
AD_ID := :NEW.ADVERTISEMENT_ID;
PROD_ID := :NEW.PRODUCT_ID;
PROD_NAME := :NEW.PRODUCT_NAME;
MSG_TO := USERNAME_FROM_AD_ID(AD_ID);
MSG_CONT := 'Dear '||MSG_TO||', We have received your advertisement. Your advertisement_id is '||AD_ID||'. Your posted product_id is '||PROD_ID||' and product_name is '||PROD_NAME||'. Please wait for admin approval for your advertisement before posting. You will be notified with this thread. Feel free to ask any kind of question about your advertisement. Enjoy buying and selling with us. Have a good day!';
INSERT INTO chat
VALUES(CHAT_SEQUENCE.NEXTVAL, MSG_CONT, SYSDATE, 'bikroy', MSG_TO);
dbms_output.put_line('USER HAS POSTED AD');
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('NO DATA FOUND') ;
WHEN TOO_MANY_ROWS THEN
DBMS_OUTPUT.PUT_LINE('MORE THAN ONE DATA FOUND') ;
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('UNKNOWN ERROR OCCURED') ;
END;
/
-----------------------------------------------------------------------------------------------------------------------------------------------
---------------Submission of Job Ad notification msg (before confirmation) -------------------------------------------------------------------
CREATE OR REPLACE TRIGGER JOB_AD_SUBMISSION_MSG
AFTER INSERT
ON JOB
FOR EACH ROW
DECLARE
MSG_TO VARCHAR2(20);
AD_ID VARCHAR2(20);
J_ID VARCHAR2(20);
J_NAME VARCHAR2(500);
MSG_CONT VARCHAR2(2000);
BEGIN
AD_ID := :NEW.ADVERTISEMENT_ID;
J_ID := :NEW.JOB_ID;
J_NAME := :NEW.JOB_TYPE ||' - '||:NEW.DESIGNATION||' of APPROX SALARY - '||:NEW.SALARY;
MSG_TO := USERNAME_FROM_AD_ID(AD_ID);
MSG_CONT := 'Dear '||MSG_TO||', We have received your advertisement. Your ADVERTISEMENT ID is '||AD_ID||'. Your posted JOB ID is '||J_ID||' and JOB is '||J_NAME||'. Please wait for admin approval for your advertisement before posting. You will be notified with this thread. Feel free to ask any kind of question about your advertisement. Enjoy buying and selling with us. Have a good day!';
INSERT INTO chat
VALUES(CHAT_SEQUENCE.NEXTVAL, MSG_CONT, SYSDATE, 'bikroy', MSG_TO);
dbms_output.put_line('USER HAS POSTED AD');
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('NO DATA FOUND') ;
WHEN TOO_MANY_ROWS THEN
DBMS_OUTPUT.PUT_LINE('MORE THAN ONE DATA FOUND') ;
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('UNKNOWN ERROR OCCURED') ;
END;
/
---------------------------------------------------------------------------------------------------------------------------------------
---------------JOB AD CONFIRMED BY ADMIN MSG ------------------------------------------------------------------------------------------
CREATE OR REPLACE TRIGGER JOB_AD_CONFIRMATION_MSG
AFTER UPDATE
--OF ADVERTISEMENT_TYPE
ON ADVERTISEMENT
FOR EACH ROW
DECLARE
MSG_TO VARCHAR2(20);
MSG VARCHAR2(2000);
AD_ID VARCHAR2(20);
J_ID VARCHAR2(20);
J_NAME VARCHAR2(500);
BEGIN
MSG_TO := :NEW.USERNAME;
AD_ID := :NEW.ADVERTISEMENT_ID;
J_ID := JOB_ID_FROM_AD_ID(AD_ID);
dbms_output.put_line(J_ID);
J_NAME := JOB_NAME_FROM_JOB_ID(J_ID);
dbms_output.put_line(J_NAME);
MSG := 'Dear '||MSG_TO||', Your previously submitted job advertisement of '||J_NAME||' has been approved by bikroy-admin and posted on bikroy.com wall. Your submitted JOB ID is '||J_ID||'. Feel free to ask any kind of question about your advertisement. Enjoy buying and selling with us. Have a good day!';
INSERT INTO chat
VALUES(CHAT_SEQUENCE.NEXTVAL, MSG, SYSDATE, 'bikroy', MSG_TO);
dbms_output.put_line('JOB AD POSTED TO BIKROY WALL');
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('NO DATA FOUND') ;
WHEN TOO_MANY_ROWS THEN
DBMS_OUTPUT.PUT_LINE('MORE THAN ONE DATA FOUND') ;
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('UNKNOWN ERROR OCCURED') ;
END;
/
-----------------------------------------------------------------------------------------------------------------------------------------
---------------PRODUCT AD CONFIRMED BY ADMIN MSG ----------------------------------------------------------------------------------------
CREATE OR REPLACE TRIGGER PROD_AD_CONFIRMATION_MSG
AFTER UPDATE
--OF ADVERTISEMENT_TYPE
ON ADVERTISEMENT
FOR EACH ROW
DECLARE
MSG_TO VARCHAR2(20);
MSG VARCHAR2(2000);
AD_ID VARCHAR2(20);
PROD_ID VARCHAR2(20);
PROD_NAME VARCHAR2(200);
BEGIN
MSG_TO := :NEW.USERNAME;
AD_ID := :NEW.ADVERTISEMENT_ID;
PROD_ID := PROD_ID_FROM_AD_ID(AD_ID);
dbms_output.put_line(PROD_ID);
PROD_NAME := PROD_NAME_FROM_PROD_ID(PROD_ID);
dbms_output.put_line(PROD_NAME);
MSG := 'Dear '||MSG_TO||', Your previously submitted product advertisement of '||PROD_NAME||' has been approved by bikroy-admin and posted on bikroy.com wall. Your submitted PRODUCT ID is '||PROD_ID||'. Feel free to ask any kind of question about your advertisement. Enjoy buying and selling with us. Have a good day!';
INSERT INTO chat
VALUES(CHAT_SEQUENCE.NEXTVAL, MSG, SYSDATE, 'bikroy', MSG_TO);
dbms_output.put_line('PRODUCT AD POSTED TO BIKROY WALL');
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('NO DATA FOUND') ;
WHEN TOO_MANY_ROWS THEN
DBMS_OUTPUT.PUT_LINE('MORE THAN ONE DATA FOUND') ;
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('UNKNOWN ERROR OCCURED') ;
END;
/
----------------------------------------------------------------------------------------------------------------------------------------------