SQL String Functions – SQL Tutorial | Software Testing Material

SQL String Functions:

In this post, we see SQL String Functions in detail.

LEN() – It returns the length of the value in a text field
LOWER() – It converts character data to lower case
UPPER() – It converts character data to upper case
SUBSTRING() – It extracts characters from a text field
LTRIM() – It is to remove all white space from the beginning of the string
RTRIM() – It is to remove all white space at the end of the string
CONCAT() – Concatenate function combines multiple character strings together.
REPLACE() –  To update the content of a string.

Let’s see each String function in detail.

LEN():

Syntax:

1
SELECT LEN(column_name) FROM table_name;

Example:

1
SELECT LEN(Playername) AS LengthPlayername FROM SCOREBOARD WHERE Playername = ‘Sachin’;

LOWER():

Syntax:

1
SELECT LOWER(column_name) FROM table_name;

Example:

1
SELECT LOWER(Playername) AS Playername FROM SCOREBOARD WHERE Playername = ‘Sachin’;

UPPER():

Syntax:

1
SELECT UPPER(column_name) FROM table_name;

Example:

1
SELECT UPPER(Playername) AS Playername FROM SCOREBOARD WHERE Playername = ‘Sachin’;

SUBSTRING() :

Syntax:

1
SELECT SUBSTRING(column_name,start,length) AS some_name FROM table_name;

Example:

1
SELECT SUBSTRING(Playername, 3, len(Playername)) AS Playername FROM SCOREBOARD WHERE Playername = ‘Sachin’;

LTRIM:

Syntax:

1
SELECT LTRIM(Playername) FROM SCOREBOARD;

RTRIM:

Syntax:

1
SELECT RTRIM(Playername) FROM SCOREBOARD;

CONCAT:

Syntax:

1
SELECT City+Country from CUSTOMERS;

REPLACE:

Syntax:

1
SELECT REPLACE (City, ‘C’, ‘ZZZZ’) FROM CUSTOMERS;

Check out the complete SQL Tutorial by clicking on below link:

SQL Tutorial – Complete