UCASE() and LCASE() are functions in MySQL used to convert strings to uppercase and lowercase, respectively.
The UCASE() function takes a string as an argument and returns the uppercase version of the string.
For example:
SELECT UCASE('hello world') AS UpperCaseString;
This will return the string "HELLO WORLD".
The LCASE() function takes a string as an argument and returns the lowercase version of the string. For example:
SELECT LCASE('Hello World') AS LowerCaseString;
This will return the string "hello world".
What is in our table:
mysql> SELECT * FROM Stores;
+------+--------+------------+-----------------+-----------+-------+
| s_id | city | store_name | product | available | price |
+------+--------+------------+-----------------+-----------+-------+
| 1 | London | London_1 | Gold PSU | 153 | 100 |
| 2 | London | London_2 | Gold PSU | 75 | 100 |
| 3 | Berlin | Berlin_1 | Green PSU | 50 | 120 |
| 4 | Berlin | Berlin_2 | XYZ Motherboard | 5 | 75 |
| 5 | Moscow | Moscow_1 | Extension Cable | 50 | 25 |
| 6 | Moscow | Moscow_2 | LPT Cables | 500 | 10 |
| 7 | Miami | Miami_1 | COM Cables | 1450 | 5 |
| 8 | Paris | Paris_1 | NIC | 350 | 15 |
+------+--------+------------+-----------------+-----------+-------+
8 rows in set (0.00 sec)
mysql>
UCASE usage:
mysql> SELECT UCASE(product) AS Products FROM Stores;
+-----------------+
| Products |
+-----------------+
| GOLD PSU |
| GOLD PSU |
| GREEN PSU |
| XYZ MOTHERBOARD |
| EXTENSION CABLE |
| LPT CABLES |
| COM CABLES |
| NIC |
+-----------------+
8 rows in set (0.02 sec)
mysql>
Our code executes a SELECT statement on the "Stores" table in MySQL. The query uses the UCASE() function to convert the values in the "product" column to uppercase, and renames the resulting column as "Products" using the AS keyword.
The resulting "Products" column contains the same values as the "product" column, but with all letters converted to uppercase.
LCASE usage:
mysql> SELECT LCASE(product) AS Products FROM Stores;
+-----------------+
| Products |
+-----------------+
| gold psu |
| gold psu |
| green psu |
| xyz motherboard |
| extension cable |
| lpt cables |
| com cables |
| nic |
+-----------------+
8 rows in set (0.00 sec)
mysql>
The LCASE()
function is a MySQL string function that converts a string to lowercase.
Here, it is applied to the "product" column of the "Stores" table, which contains strings representing product names in uppercase, and returns their lowercase equivalents in the "Products" column of the query result.
No comments:
Post a Comment