Member-only story
There are various string functions in SQL that allow you to manipulate and perform operations on string data.
1. CONCAT (or ||):
- Concatenates two or more strings together.
SELECT CONCAT(first_name, ' ', last_name) AS full_name
FROM employees;
2. LENGTH (or LEN):
- Returns the length (number of characters) of a string.
SELECT LENGTH(product_name) AS name_length
FROM products;
3. UPPER:
- Converts all characters in a string to uppercase.
SELECT UPPER(product_name) AS upper_case_name
FROM products;
4. LOWER:
- Converts all characters in a string to lowercase.
SELECT LOWER(product_name) AS lower_case_name
FROM products;
5. SUBSTRING (or SUBSTR):
- Extracts a substring from a string.
SELECT SUBSTRING(product_name, 1, 3) AS first_three_chars
FROM products;
6. TRIM:
- Removes leading and trailing spaces from a string.
SELECT TRIM(product_name) AS trimmed_name
FROM products;