Use the text functions UPPER(), LOWER() and LENGTH()
Expt. No.31
Page No.62
UPPER, LOWER, LENGTH
Aim
To display teacher names in upper and lower case along with the length of each name.
Concepts used
Queries
USE school;SELECT tname, UPPER(tname), LOWER(tname), LENGTH(tname) FROM teacher;SELECT UCASE('byteboard'), LCASE('CBSE');
A marked line continues the line above it. In your file, write it on the same line.
Table used
Table: teacher
+-----+------------+---------+--------+------------+ | tid | tname | subject | salary | doj | +-----+------------+---------+--------+------------+ | 1 | Meena Rao | Maths | 72000 | 2012-07-16 | | 2 | Arun Kumar | Physics | 68000 | 2015-04-01 | | 3 | Sana Khan | IP | 75000 | 2010-11-23 | | 4 | Vikas Jain | English | 61000 | 2019-06-10 | +-----+------------+---------+--------+------------+
Output
mysql> USE school;
Database changed
mysql> SELECT tname, UPPER(tname), LOWER(tname), LENGTH(tname) FROM teacher;
+------------+--------------+--------------+---------------+
| tname | UPPER(tname) | LOWER(tname) | LENGTH(tname) |
+------------+--------------+--------------+---------------+
| Meena Rao | MEENA RAO | meena rao | 9 |
| Arun Kumar | ARUN KUMAR | arun kumar | 10 |
| Sana Khan | SANA KHAN | sana khan | 9 |
| Vikas Jain | VIKAS JAIN | vikas jain | 10 |
+------------+--------------+--------------+---------------+
4 rows in set
mysql> SELECT UCASE('byteboard'), LCASE('CBSE');
+--------------------+---------------+
| UCASE('byteboard') | LCASE('CBSE') |
+--------------------+---------------+
| BYTEBOARD | cbse |
+--------------------+---------------+
1 row in set
✓ Printed by running this query set, not typed by hand.
Result
Each name was shown in capitals and in small letters, with its length counting the space (e.g. "Meena Rao" has 9 characters). UCASE and LCASE gave the same results as UPPER and LOWER.
Viva voce: what the examiner may ask
01Are UPPER and UCASE different?
No. They are two names for the same function.
02Does LENGTH count spaces?
Yes. Every character, including spaces, is counted.
03Do these functions change the data in the table?
No. They change only what is displayed.
Variations for the lab test
- Display the names whose length is more than 9.
- Display subjects in uppercase.
- Display the length of the longest name using MAX(LENGTH(tname)).
! Common mistake Writing
UPPER tname without brackets is a syntax error.