Chapter 6 - MySQL Function
Chapter 6 - MySQL Function
6.1 Introduction
Date can be manipulated in queries through functions supported by
SQL.
“ A function is a special type of predefined command set that
performs some operation and returns a single value.”
Functions operate on zero, one two or more values that are provided
to them.
The values that are provided to functions are called parameters or
arguments.
The MySQL functions have been categorised into various categorised,
such as Text functions, Mathematical functions , Date and Time
functions and so on.
6.2 Text/String Function
The String functions of MySQL can manipulate the text string in
many ways.Some commonly used string functions are as follows:
1. CHAR( )
This function returns the character for each integer passed.
Syntax
CHAR(value 1,value 2)
Returns a string made up of the ASCII representation of the decimal
value list.
String in numeric format are converted to a decimal value.
Null values are ignored.
Argument type : Integer Return Value : String
Example 1
mysql>SELECT CONCAT ( -
>name ,aggregate) As “Name -
>Marks” FROM student
->WHERE age = 14 OR age = 16;
Example 3
mysql>SELECT CONCAT ( -
>name ,aggregate) As “Name -
>Marks” FROM student
->WHERE age = 14 OR age = 16;
3. LOWER / LCASE
This function removes leading spaces i.e. spaces from the left
of given string.
Syntax
LTRIM( str )
Removes soaces from the left of argument str with initial characters
removed.
Argument type : String Return value : String
Syntax
RTRIM( str )
Removes str, with trailing spaces i.e. spaces from the right of given
string.
Argument type : String, Return value : String
This function searches for given second into the given first
string
Syntax
INSTR( str1 , str2 )
Searches str1 for str2 and returns the position.