LAB 4
AIM-To Implement built in functions in SQL
Date and time function-
i. Function: current_time
Purpose:returns the current date and time.
Syntax: select curtime() as time,curdate() as date;
Output:
ii. Function: Dateadd
Purpose: Adds a time/date interval to a date and then
returns the date
Syntax:select date_add(curdate(),interval 20 day);
Output:
Numeric function-
i. Function: Round
Purpose: Rounds a number to a specified number of
decimal places.
Syntax : select round (number);
Output:
ii. Function: Ceil
Purpose: returns the smallest integer value which is
greater than or equal to a number.
Syntax: select ceil(number);
Output:
iii. Function: Floor
Purpose: returns the largest integer value which is
less than or equal to a number.
Syntax: select floor(number);
Output:
iv. Function: Sign
Purpose: returns the sign of a number.
Syntax: select sign(sign number);
Output:
v. Function: Abs
Purpose: returns the absolute value of a number.
Syntax:select abs(number);
Output:
Math function-
i. Function: Power
Purpose: Returns the value of a number raised to
the power of another number.
Syntax:select power(x,y);
Output:
ii. Function: mod
Purpose: function is used to get the remainder
from a division.
Syntax: select mod(x,y);
Output:
iii. Function: Exp
Purpose: Returns e raised to the power of a
specified number
Syntax: select exp(number);
Output:
iv. Function: Sqrt
Purpose: Returns the square root of a number
Syntax: select sqrt(number);
Output:
v. Function: sin,cos,tan
Purpose: Returns the sine ,cosine , tangent of a
number respectively.
Syntax: select cos(degree); select sin(degree);
Output:
vi. Function: log
Purpose: Returns the natural logarithm of a number, or
the logarithm of a number to a specified base
Syntax: select log(number);
Output:
vii. Function: Pi
Purpose: Returns the value of PI
Syntax: select pi()
Output:
String function-
i. Function: Upper
Purpose: function converts a string to upper-case.
Syntax: select upper(‘string’);
Output:
ii. Function: Lower
Purpose: function converts a string to upper-case.
Syntax: select lower(‘string’);
Output:
iii. Function: Ltrim
Purpose: function removes leading spaces from a string.
Syntax: select ltrim(‘string’);
Output:
iv. Function: Rtrim
Purpose: function removes trailing spaces from a string
Syntax: select rtrim(‘string’);
Output:
v. Function: Concat
Purpose: The CONCAT() function adds two or more strings
together.
Syntax: select concat(‘string1’,’string2’);
Output:
vi. Function: Len
Purpose: function returns the length of a string.
Syntax: select length(‘string’);
Output:
vii. Function: Replace
Purpose: replaces all occurrences of a substring within
a string, with a new substring.
Syntax: select replace(‘string’,’substring’,’newstring’);
Output: