-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathextract_string.sql
More file actions
65 lines (49 loc) · 1.54 KB
/
extract_string.sql
File metadata and controls
65 lines (49 loc) · 1.54 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
/* Use a string of 12 characters for experimenting with string extraction */
select
'abcdefghijkl' test_string;
/* Extract the frist 3 characters of a string */
select
substring('abcdefgh' from 1 for 3);
/* Select the first three characters of the string */
select
substring('abcdefghijkl' from 1 for 3) test_string;
/* Select a subset from the middle of the string */
select
substring('abcdefghijkl' from 5 for 3) test_string;
/* Select a substring starting in the middle and going for the lenght of the string */
select
substring('abcdefghijkl' from 5) test_string;
/* Select Assistant job tiltles, and extract the main job category */
select
job_title, substring(job_title from 10) asst_category
from
staff
where
job_title like 'Assistant%';
/* Replace a substring with another string using overlay */
select
overlay('abcdefghijkl' placing 'CDEF' from 3 for 4);
/* Change Assistant to Asst in job title */
select
job_title, overlay(job_title placing 'Asst. ' from 1 for 10)
from
staff
where
job_title like 'Assistant%';
/* Select staff wtih job titles that start with Assistant */
select
job_title, position('Assistant' in job_title)
from
staff
where
job_title like '%Assistant%';
/* Replace a substring with another string using overlay */
select
overlay('abcdefghijkl' placing 'CDEF' from 3 for 4);
/* Change Assistant to Asst in job title */
select
job_title, overlay(job_title placing 'Asst. ' from position('Assistant' in job_title) for 10)
from
staff
where
job_title like '%Assistant%';