-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtst_set_doc_number.sql
More file actions
79 lines (71 loc) · 2.13 KB
/
tst_set_doc_number.sql
File metadata and controls
79 lines (71 loc) · 2.13 KB
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
/*
Find and format documents that meet the criteria for correct formatting
@author Jeremy Heminger <jheminger@tstwater.com>, <contact @jeremyheminger.com>
@version 1.0.5
When setting a document to 'Released' status set the Document # to an ISO standard
if the description matches the pattern AA_####-#### OR AAA_####-####
Example: HR_1000-0001 This is a test.pdf
OR
ENG_1000-0001 This is a test.pdf
then set the document number to the prefix of the document title
@ver 1.0.5 - finally realized the error was in the datatype for n_len
@broken - TRUE
@ver 1.0.5 still fails at line 76 for some reason
despite setting the data type to number
*/
CREATE OR REPLACE TRIGGER tst_set_doc_number
BEFORE UPDATE ON external_doc
FOR EACH ROW
WHEN (
new.STATUS = 'Released'
-- current document# is either '' or is ONLY a number
AND (
new.DOC_LIBRARY_ID = ''
OR
REGEXP_LIKE(new.DOC_LIBRARY_ID,'(\d+)')
)
)
DECLARE
-- init variables
b_update boolean;
n_len number := 1;
BEGIN
-- reset for each loop
b_update := FALSE;
-- check if criteria is met
-- AAA_####-####_AA
IF b_update = FALSE AND REGEXP_LIKE(:new.DESCRIP,'([A-Z][A-Z][A-Z])_(\d{4})-(\d{4})_([A-Z])') THEN
b_update := TRUE;
n_len := 15;
END IF;
-- AA_####-####_AA
IF b_update = FALSE AND REGEXP_LIKE(:new.DESCRIP,'([A-Z][A-Z])_(\d{4})-(\d{4})_([A-Z])') THEN
b_update := TRUE;
n_len := 14;
END IF;
-- AAA_####-####_A
IF b_update = FALSE AND REGEXP_LIKE(:new.DESCRIP,'([A-Z][A-Z][A-Z])_(\d{4})-(\d{4})_([A-Z])') THEN
b_update := TRUE;
n_len := 15;
END IF;
-- AA_####-####_A
IF b_update = FALSE AND REGEXP_LIKE(:new.DESCRIP,'([A-Z][A-Z])_(\d{4})-(\d{4})_([A-Z])') THEN
b_update := TRUE;
n_len := 14;
END IF;
-- AAA_####-####
IF b_update = FALSE AND REGEXP_LIKE(:new.DESCRIP,'([A-Z][A-Z][A-Z])_(\d{4})-(\d{4}))') THEN
b_update := TRUE;
n_len := 13;
END IF;
-- AA_####-####
IF b_update = FALSE AND REGEXP_LIKE(:new.DESCRIP,'([A-Z][A-Z])_(\d{4})-(\d{4}))') THEN
b_update := TRUE;
n_len := 12;
END IF;
-- can we update?
IF b_update = TRUE THEN
-- update
:new.DOCNO := substr(:new.DESCRIP,0,n_len);
END IF;
END;