String-1
String-1
----CREATE TABLE
1
---INSERT RECORDS
2
A. CONCAT , ||
EXAMPLE:-
USING “ | | “
3
4. SELECT 'ANAND' || ' KUMAR' || ' JHA' AS FULL_NAME;
4
7. CONCANATING TWO COLOUMN USING “ || ”.
B. CONCAT_WS
SYNTAX:-
CONCAT_WS( <separator> , <expression1> [ , <expressionN> ... ] )
EXAMPLE:-
1. SELECT CONCAT_WS('-', 'KA','India') as state_country;
5
2. CONCATENATE TWO COLUMN AND USING SEPARATER AS ‘ - ‘ , SEPARATE TWO
COLUMN.
SELECT CONCAT_WS(‘ –‘, AGENT_CODE, AGENT_NAME) AS AGENT_DETAIL
FROM AGENTS;
C. LENGTH, LEN
We can find the length of a string using the LENGTH function.
SYNTAX:
LENGTH(<expression>)
LEN(<expression>)
EXAMPLE:
1 . SELECT LEN ('ANAND KUMAR JHA') AS LENGTH;
6
D. SUBSTRING, SUBSTR
EXAMPLE:-
OR
7
select concat(substring('ANAND KUMAR JHA',1,1),substring('ANAND KUMAR
JHA',7,1)) AS partial_name;
You can remove leading and trailing spaces from a string using the TRIM
Function.
We have three type of TRIM Function.
LTRIM
RTRIM
TRIM
LTRIM:
Removes leading characters, including whitespace, from a string.
SYNTAX:
LTRIM( <expression> [ character])
EXAMPLE:
1. Remove leading ‘0’ and ‘#’ characters from a string:
9
RTRIM
Removes trailing characters, including whitespace, from a string.
SYNTAX:
RTRIM( <expression> [ character])
EXAMPLE:-
10
TRIM
Removes leading and trailing characters from a string.
SYNTAX:-
TRIM( <expression> [ character])
EXAMPLE:-
11
F. REVERSE
SYNTAX:-
REVERSE(STRING)
EXAMPLE:-
12
G. REPLACE
Removes all occurrences of a specified substring, and optionally replaces them with
another string.
The returned value is the string after all replacements have been done.
SYNTAX:-
REPLACE( <subject> , <pattern> [ , <replacement> ] )
EXAMPLE:-
3. Replacing whitespace.
SELECT REPLACE(' T E S T I N G 1 2 3 4 ',' ');
13
H. REPEAT
SYNTAX:-
REPEAT(INPUT , NUMBER)
EXAMPLE:-
I. LIKE
SYNTAX:-
14
There are two common wildcard characters used with the LIKE
operator:
EXAMPLE:-
1. If you want to find all rows where the agent_name column starts with
"An" .
2. If you want to find all rows where the agent_name contain “ar” in
between .
15
3. If you want to find all rows where the agent_name second letter
should be “l” .
Select * from AGENTS
Where AGENT_NAME LIKE ‘_l%’;
4. If you want to find all rows where the agent_name third letter should
be “a” .
Select * from AGENTS
Where AGENT_NAME LIKE ' a%';
5. If you want to find all rows where the agent_name last letter should
be “r” .
Select * from AGENTS
Where AGENT_NAME LIKE '%r';
16
6. If you want to find all rows where the agent_name last second letter
should be “a” .
Select * from AGENTS
Where AGENT_NAME LIKE '%a_';
7. If you want to find all rows where the agent_name second last and
third letter should be “a” and “m” respectively.
Select * from AGENTS
Where AGENT_NAME LIKE '%ma_';
8. If you want to find all rows where the agent_code contain “01” in
between.
select * from AGENTS
where AGENT_CODE LIKE '%01%';
17
J. SPLIT
Split function is used to split a string into multiple rows based on a delimiter. This
function is especially useful when you want to split a string into multiple values and
treat them as separate rows in your query.
SYNTAX:-
SELECT SPLIT(COLOUMN | STRING, DELIMETER)
FROM TABLE_NAME;
EXAMPLE:-
--CREATE TABLE
create or replace table aj_persons
(
NAME CHAR(10),
CHILDREN VARCHAR(30)
);
--INSERT VALUE
INSERT INTO AJ_PERSONS
VALUES('Mark','Marky,Mark Jr,Maria'),('John','Johnny,Jane');
18
SELECT * FROM AJ_PERSONS;
19
K. SPLIT_PART
Splits a given string at a specified character and returns the requested part.
If any parameter is NULL, NULL is returned.
SYNTAX:-
SELECT SPLIT_PART( STRING, DELIMETER,PART NUMBER)
EXAMPLE:-
1. Splitting the first 1st part and 2nd part of IP which is separated by delimiter “.”.
20
L. LOWER
SYNTAX :- LOWER(exp)
EXAMPLE:-
M. UPPER
It Returns the input string (expr) with all characters converted to
lowercase.
SYNTAX :- UPPER(exp)
EXAMPLE:-
21
N. INITCAP
It returns the input string exp with the first letter of each word in
uppercase and the subsequent letters in lowercase.
SYNTAX:- INITCAP(EXP)
EXAMPLE:-
22