Introduction
String functions help us change and check text in databases easily. They make searching and organizing text data simple and fast.
FUNCTION_NAME(column_name) -- Example: UPPER(name) -- Example: LENGTH(description)
SELECT UPPER(name) FROM users;
SELECT LENGTH(description) FROM products;
SELECT CONCAT(first_name, ' ', last_name) AS full_name FROM employees;
SELECT TRIM(email) FROM contacts;
CREATE TABLE customers ( id INT, first_name VARCHAR(50), last_name VARCHAR(50), email VARCHAR(100) ); INSERT INTO customers VALUES (1, 'Alice', 'Smith', ' alice@example.com '), (2, 'Bob', 'Brown', 'bob@example.com'), (3, 'Carol', 'Davis', ' carol@example.com'); SELECT id, CONCAT(UPPER(first_name), ' ', UPPER(last_name)) AS full_name, TRIM(email) AS clean_email FROM customers;
UPPER() or LOWER() in SQL queries?UPPER() and LOWER() change the case of text data to uppercase or lowercase.name in SQL?LEFT() function extracts a specified number of characters from the beginning of a string.LEFT(name, 3) correctly gets the first 3 characters. Other options either extract from the wrong side or have incorrect syntax.users with a column email, what will this query return?SELECT LENGTH(TRIM(email)) FROM users;
SELECT * FROM employees WHERE name LIKE 'Jo%';
|| or CONCAT(). The CONCAT() function can take multiple arguments.CONCAT(first_name, ' ', last_name), correctly adding a space between first and last names. SELECT first_name || ' ' || last_name AS full_name FROM users; uses || which works in some systems but not all. SELECT CONCAT(first_name, last_name) AS full_name FROM users; misses the space. SELECT first_name + ' ' + last_name AS full_name FROM users; uses + which is invalid for strings in SQL.Pass the test and this pattern moves unknown