Page 172 - Informatics_Practices_Fliipbook_Class12
P. 172
or
SELECT FName, LName, DOB
FROM EMPLOYEE
WHERE DOB LIKE '1980%';
Execution of either of the above two queries, will produce the following output (Table 4.27):
FName LName DOB
Raj Reddy 1980-06-13
Naveen Basra 1980-09-24
Table 4.27 Employees born in 1980
4.4.16 Math Functions
Math functions can be used to perform various mathematical calculations and manipulate numerical data in MySQL
queries. Below we illustrate the use of the mathematical functions POWER(), ROUND(), and MOD() in MySQL.
1. POWER(x, y)
The POWER() function calculates the value: x raised to the power y(x ).
y
Example:
Suppose, we want to calculate the cube of a number (say, 2). We can use the POWER() function as follows:
SELECT POWER(2, 3);
Output: 8
In this example, the POWER(2, 3) calculates 23, resulting in 8.
2. ROUND(x, d)
The ROUND() function is used to round a number to a specified number of decimal places.
Example:
SELECT ROUND(3.14159, 2);
Output: 3.14
In the above example, ROUND(3.14159, 2) rounds the number 3.14159 to 2 decimal places, resulting in
3.14.
3. MOD(x, y):
The MOD() function returns the remainder when x is divided by y.
Example:
SELECT MOD(10, 3);
Output: 1
In the above example, MOD(10, 3) returns 1 as the remainder when 10 is divided by 3.
4.4.17 Text Functions
Text functions are used for manipulating and extracting information from text data. Below we illustrate the use of
some common MySQL text functions with examples.
1. UCASE() / UPPER()
The UCASE() or UPPER() function is used to convert a string to uppercase.
Example:
Let us convert the string "hello world" to uppercase. For this purpose, we can use either of the functions UCASE()
or UPPER, as shown below:
158 Touchpad Informatics Practices-XII

