-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path8.Changing Case with UPPER and LOWER(String).sql
More file actions
61 lines (45 loc) · 1.17 KB
/
8.Changing Case with UPPER and LOWER(String).sql
File metadata and controls
61 lines (45 loc) · 1.17 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
-- Things to note sql.format.com ==> used to format querys
-- 1. REVERSE ==> used to reverse the string
-- example
SELECT
REVERSE('Good-Morning');
show databases;
USE book_shop;
SELECT
REVERSE(author_fname)
FROM books;
--
-- 'woof' 'foow'
SELECT
concat('woof', REVERSE('woof'));
-- Use on author table (Palindrome)
SELECT
concat(author_fname, REVERSE(author_fname))
FROM books;
-- 2. CHAR_LENGTH == COUNT CHARACTERS IN STRINGS
-- example
SELECT
CHAR_LENGTH('Hello worldskjwoeheois');
-- used on table
SELECT
author_lname,
CHAR_LENGTH(author_lname) AS 'length'
FROM books; -- apply on lname
SELECT
author_fname,
CHAR_LENGTH(author_fname) AS 'length'
FROM books; -- apply on fname
-- To print following format
-- "Egger is 6 characters long"
SELECT
concat(author_lname, ' is ', CHAR_LENGTH(author_lname), ' characters long ')
FROM books;
-- UPPER() AND LOWER() ==> CHANGE A STRING'S CASE
-- Example UPPER
select upper('Hello World');
-- Example Lower()
select lower('Hello World');
-- use on book data
select upper(title) from books;
select concat('MY FAVORITE BOOK IS THE', UPPER(title)) from books;
SELECT CONCAT('MY FAVORITE BOOK IS ', LOWER(title)) FROM books;