-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathString Function.sql
More file actions
69 lines (44 loc) · 1.67 KB
/
String Function.sql
File metadata and controls
69 lines (44 loc) · 1.67 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
--STRING FUNCTION
CREATE TABLE string_data (
id SERIAL PRIMARY KEY,
first_name VARCHAR(100),
last_name VARCHAR(100),
full_text TEXT,
email VARCHAR(150),
city VARCHAR(100)
);
INSERT INTO string_data
(first_name, last_name, full_text, email, city)
VALUES
('Amit', 'Verma', 'SQL is easy to learn', 'amit@gmail.com', 'Delhi'),
('Neha', 'Joshi', 'PostgreSQL string functions practice', 'neha@yahoo.com', 'Mysore'),
('Karan', 'Mehta', 'Learning database concepts', 'karan@outlook.com', 'Ahmedabad'),
('Pooja', 'Nair', 'Working with SQL queries', 'pooja@hotmail.com', 'Kochi'),
('Rohit', 'Das', 'String manipulation in PostgreSQL', 'rohit@icloud.com', 'Kolkata');
SELECT * FROM string_data;
--GET ALL CAEGORIES IN UPPERCASE
SELECT UPPER(first_name) AS UPPERCASE
FROM string_data;
--GET ALL CAEGORIES IN LOWERCASE
SELECT LOWER(first_name) AS UPPERCASE
FROM string_data;
--GET LENGH OF full_text
SELECT LENGTH (full_text) AS Length
FROM string_data;
--GET LENGH OF full_text
SELECT CONCAT (first_name,' ',last_name) AS Full_name
FROM string_data;
--EXTRACT FIRST 5 CHARACTERS OF full_text
SELECT SUBSTRING(full_text,1,5) AS short_name
FROM string_data;
--REMOVE LENGHT & TRAILING SPACE FROM STRING
SELECT LENGTH(' monitor ') AS Length_of_monitor,
TRIM(' monitor ') AS trimmed_text,
LENGTH(TRIM(' monitor ')) AS Length_trimmed_text;
--REPLACE THE WORD VERMA WITH SHARMA
SELECT REPLACE (last_name,'Verma','Sharma')
FROM string_data;
SELECT * FROM string_data;
--GET LEFT & RIGHT CHARCATERS
SELECT LEFT (email,4) FROM string_data;
SELECT RIGHT (email,4) FROM string_data;