-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_doc_number_format.dev.sql
More file actions
44 lines (40 loc) · 1.12 KB
/
update_doc_number_format.dev.sql
File metadata and controls
44 lines (40 loc) · 1.12 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
DECLARE
-- init variables
b_update boolean;
n_len smallint(2) := 0;
BEGIN
FOR n IN (SELECT * FROM external_doc
WHERE (
DOC_LIBRARY_ID = ''
OR
REGEXP_LIKE(DOC_LIBRARY_ID,'(\d+)')
)
AND STATUS != 'Checked Out'
AND STATUS != 'New')
LOOP
-- reset for each loop
b_update := FALSE;
-- check if criteria is met
IF REGEXP_LIKE(n.DESCRIP,'([A-Z][A-Z][A-Z]_(\d{4})-(\d{4}))_[A-Z]') THEN -- AA_####-####_A
b_update := TRUE;
n_len := 15;
END IF;
IF b_update = FALSE AND REGEXP_LIKE(n.DESCRIP,'([A-Z][A-Z]_(\d{4})-(\d{4}))_[A-Z]') THEN -- AAA_####-####_A
b_update := TRUE;
n_len := 14;
END IF;
IF b_update = FALSE AND REGEXP_LIKE(n.DESCRIP,'([A-Z][A-Z][A-Z]_(\d{4})-(\d{4}))') THEN -- AAA_####-####
b_update := TRUE;
n_len := 13;
END IF;
IF b_update = FALSE AND REGEXP_LIKE(n.DESCRIP,'([A-Z][A-Z]_(\d{4})-(\d{4}))') THEN -- AA_####-####
b_update := TRUE;
n_len := 12;
END IF;
-- if criteria is met
IF b_update = TRUE THEN
-- update
UPDATE external_doc SET DOCNO = substr(n.DESCRIP,0,n_len) where id = n.id;
END IF;
END LOOP;
END;