MySQL LOWERcase/LCASE() Functions with Simple Examples – MPS


70 / 100

MySQL LOWERcase/LCASE() Functions with Simple Examples – MPS

This tutorial explains MySQL LOWER()/LCASE() capabilities which convert the higher case characters of a string to the LOWERcase. We’ll describe the functioning of this technique with the assistance of straightforward examples.

MySQL LOWER()/LCASE() Functions

As said initially, LOWER() is a built-in MySQL perform which modifications a string worth to the LOWERcase. So, let’s now see the main points and take a look at how can we use it.

Syntax

Below is the signature of this technique:

# MySQL Function to transform textual content to LOWERcase
LOWER(Given_string);

Below is the outline of the parameter used in the above perform.

+--------------+-------------------------------------+
| # Params     | # Description                       |
+--------------+-------------------------------------+
| Given_string | Input string argument in higher case |
+-------------+--------------------------------------+

MySQL additionally supplies LCASE() which is one other perform to transform a string to the LOWERcase. It takes some textual content enter and produces the outcome in capitalized format.

# Another MySQL perform to capitalize a string
LCASE(Given_string);

Later, in examples, you’ll see that each LOWER() and LCASE() are producing the same output.

MySQL UPPER()/UCASE() Functions

MySQL LOWER()/LCASE() Examples

Let’s now unveil a number of examples addressing totally different conditions.

Using LOWER()/LCASE() to transform textual content to lowercase

Both LOWER() and LCASE() capabilities can take a regular or alpha-numeric TEXT and flip to the LOWERcase. See the beneath instance.

SELECT LOWER('PYTHON PROGRAMMING');
SELECT LOWER('PYTHON VERSION 3.6');

Check the outcome/final result of the LOWER() perform beneath.

1 MySQL Workbench
python programming
python model 3.6

Next, we’ll run the identical take a look at utilizing the MySQL LCASE() perform.

SELECT LCASE('PYTHON PROGRAMMING');
SELECT LCASE('PYTHON VERSION 3.6');

You can see that LCASE() additionally produced the same as LOWER() did.

1 MySQL Workbench
python programming
python model 3.6

Calling LOWER()/LCASE() on desk fields

In this instance, we’re making use of the LOWER() on a desk column. Here, we are going to print the corporate title in capital format.

-- Using MySQL LOWER on desk information
SELECT 
    company_name, 
    LOWER(company_name) LOWER_CASE
FROM
    company_list
ORDER BY 
    company_name
LIMIT 5;

After executing the above command, the output shall be:

1 MySQL Workbench
apple
bing
ca
dell
google

Let’s now use LCASE on the identical desk and see what it does.

-- Using MySQL LCASE on desk information
SELECT 
    company_name, 
    LCASE(company_name) LCASE
FROM
    company_list
ORDER BY 
    company_name
LIMIT 5;

After executing the above command, the output is the identical:

1 MySQL Workbench
apple
bing
ca
dell
google

MySQL LOWER()/LCASE() on binary textual content

MySQL sorts such as BINARY or VARBINARY or BLOB are binary information. The LOWER() perform is not immediately suitable with these.

Hence, we first should convert them to get suitable with the LOWER() perform. See the instance beneath.

-- Convert binary textual content to string and then in LOWERcase utilizing LOWER()
SET @binary_data = BINARY 'BINARY SAMPLE TEXT';
SELECT LOWER(@binary_data), LOWER(CONVERT(@binary_data USING UTF8MB4)) LOWER_FUNC;

After execution, we get this:

1 MySQL Workbench
BINARY SAMPLE TEXT   binary pattern textual content

Similarly, we’ll now use LCASE() as an alternative of LOWER() for the above take a look at case.

-- Convert binary textual content to string and then in LOWERcase utilizing LCASE()
SET @binary_data = BINARY 'BINARY SAMPLE TEXT';
SELECT LCASE(@binary_data), LCASE(CONVERT(@binary_data USING UTF8MB4)) LCASE_FUNC;

After execution, we get this:

1 MySQL Workbench
BINARY SAMPLE TEXT   binary pattern textual content

We hope that after wrapping up this tutorial, it’s best to really feel comfy in utilizing the MySQL LOWER() and LCASE() perform. However, it’s possible you’ll apply more with examples to realize confidence.

Also, to be taught SQL from scratch to depth, do learn our step-by-step MySQL tutorial.

Recommended submit:


Source link

Have any Question or Comment?

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories

You have successfully subscribed to myprogrammingschool

There was an error while trying to send your request. Please try again.

My Programming School will use the information you provide on this form to be in touch with you and to provide updates and marketing.