Friday 20 February 2015

The LOWER Function in SQL

The LOWER function returns character, with all letters lowercase. The example presented below transforms all data in first name and job id columns to lower case.

  NOTE   Use LCASE() function for the same purpose in Microsoft Access.

NOTE
As mentioned earlier, single row functions can also be used in the WHERE clause. Let’s see an example. Running the first statement below will not yield any result. Change it so that it matches the second statement. Now you’ll get some rows. The LOWER() function in the second statement fetched the result, because all the job ids are stored in uppercase in the employees table, and you forced the query (by using the LOWER function) to first convert all the column values to lower case, match each value with the provided lower case string (pu_clerk), and then return the result.

Select first_name, last_name, job_id from employees where job_id='pu_clerk';
Select first_name, last_name, job_id from employees where lower(job_id)='pu_clerk';

    Syntax :
LOWER (character)

    SQL Statement :
SELECT    LOWER(first_name||' '||last_name) Name, LOWER(job_id) Job
FROM       employees;

    Output  :











No comments:

Post a Comment