Skip to content

Commit 62bb995

Browse files
Update 07_String_Functions.sql
1 parent 3f6f487 commit 62bb995

1 file changed

Lines changed: 25 additions & 25 deletions

File tree

scripts/07_String_Functions.sql

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
- CONCAT
1010
- LOWER
1111
- UPPER
12-
- TRIM
13-
- REPLACE
12+
- TRIM
13+
- REPLACE
1414
2. Calculation
1515
- LEN
1616
3. Substring Extraction
@@ -42,16 +42,6 @@ FROM customers
4242
SELECT
4343
UPPER(first_name) AS upper_case_name
4444
FROM customers
45-
46-
/* ==============================================================================
47-
LEN() - String Length & Trimming
48-
=============================================================================== */
49-
50-
-- Calculate the length of each customer's first name
51-
SELECT
52-
first_name,
53-
LEN(first_name) AS name_length
54-
FROM customers
5545

5646
/* ==============================================================================
5747
TRIM() - Remove White Spaces
@@ -67,6 +57,29 @@ FROM customers
6757
WHERE LEN(first_name) != LEN(TRIM(first_name))
6858
-- WHERE first_name != TRIM(first_name)
6959

60+
/* ==============================================================================
61+
REPLACE() - Replace or Remove old value with new one
62+
=============================================================================== */
63+
-- Remove dashes (-) from a phone number
64+
SELECT
65+
'123-456-7890' AS phone,
66+
REPLACE('123-456-7890', '-', '/') AS clean_phone
67+
68+
-- Replace File Extence from txt to csv
69+
SELECT
70+
'report.txt' AS old_filename,
71+
REPLACE('report.txt', '.txt', '.csv') AS new_filename
72+
73+
/* ==============================================================================
74+
LEN() - String Length & Trimming
75+
=============================================================================== */
76+
77+
-- Calculate the length of each customer's first name
78+
SELECT
79+
first_name,
80+
LEN(first_name) AS name_length
81+
FROM customers
82+
7083
/* ==============================================================================
7184
LEFT() & RIGHT() - Substring Extraction
7285
=============================================================================== */
@@ -92,19 +105,6 @@ SELECT
92105
first_name,
93106
SUBSTRING(TRIM(first_name), 2, LEN(first_name)) AS trimmed_name
94107
FROM customers
95-
96-
/* ==============================================================================
97-
REPLACE() - Replace or Remove old value with new one
98-
=============================================================================== */
99-
-- Remove dashes (-) from a phone number
100-
SELECT
101-
'123-456-7890' AS phone,
102-
REPLACE('123-456-7890', '-', '/') AS clean_phone
103-
104-
-- Replace File Extence from txt to csv
105-
SELECT
106-
'report.txt' AS old_filename,
107-
REPLACE('report.txt', '.txt', '.csv') AS new_filename
108108

109109
/* ==============================================================================
110110
NESTING FUNCTIONS

0 commit comments

Comments
 (0)