SQL LOWER()
The SQL LOWER() function converts all characters in a given string to lowercase. This function is useful for case-insensitive comparisons, data normalization, and ensuring consistent formatting for text fields.
The LOWER() function is widely supported in SQL databases, including MySQL, SQL Server, PostgreSQL, and Oracle.
In this tutorial, we will go through SQL LOWER() String function, its syntax, and how to use this function in SQL statements for string operations, with the help of well detailed examples.
Syntax of SQL LOWER() Function
The basic syntax of the SQL LOWER() function is:
LOWER(string);
Each part of this syntax has a specific purpose:
- string: The text to be converted to lowercase. This can be a column, variable, or text literal.
The LOWER() function returns the string with all characters in lowercase.
Setup for Examples: Creating the Database and Table
We’ll create a sample products table with fields product_name and description to demonstrate the LTRIM() function examples.
1. First, create a new database called store:
CREATE DATABASE store;
2. Select the store database to work with:
USE store;
3. Create a table named products with fields product_id, product_name, and description:
CREATE TABLE products (
product_id INT PRIMARY KEY AUTO_INCREMENT,
product_name VARCHAR(100),
description TEXT
);
4. Insert sample data into the products table to use with the LTRIM() function examples:
INSERT INTO products (product_name, description)
VALUES
(' Laptop Pro', ' High-performance laptop with a sleek design.'),
('Wireless Mouse ', 'Compact and easy to use. '),
(' Smartphone XL', ' Large screen smartphone with powerful features.'),
('Tablet', 'Versatile tablet for work and play.');
With this setup complete, we can run the LTRIM() function examples to test and view results in the products table.
