Dbms Practical 09

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

Maharishi Markandeshwar deemed to be university, Mullana, Ambala

Name:- Raunak mishra Roll No :- 11222619


Subject:- Database Management System course code:- BCSE- 510

Practical: - 09
Aim: - To describe various MySQL functions.
(A) Mathematical functions:-
1. Floor: - Returns the largest integer values that is <= to a number.
Syntax: - select floor(23/6);

Fig 1.1
2. ceiling:- Returns the smallest integer value that is >= to a number.
Syntax:- select ceiling(23/6);

Fig 1.2
3. Truncate: - Truncates a number to the specified number of decimal places.
Syntax:- select truncate(float value, specified_number);

Fig 1.3
4. Hex: - It returns the hexadecimal encoding of an integer expression.
Syntax: - select hex(‘B’);
Maharishi Markandeshwar deemed to be university, Mullana, Ambala
Name:- Raunak mishra Roll No :- 11222619
Subject:- Database Management System course code:- BCSE- 510

Fig 1.4
5. Oct: - It return octal value of a decimal number.
Syntax:- select oct(52);

Fig 1.5
6. Truncate:- Truncates a number to the specified number of decimal places.
Syntax: - select truncate(789.369,2);

Fig 1.6
7. Bin:- It returns binary representation of a number.
Syntax:- select bin(38);

Fig 1.7
8. Sin: - Returns the sine of a number.
Maharishi Markandeshwar deemed to be university, Mullana, Ambala
Name:- Raunak mishra Roll No :- 11222619
Subject:- Database Management System course code:- BCSE- 510

Syntax: - select sin(60);

Fig 1.8
9. cos :- It returns the cosine of a number.
Syntax:- select cos(60);

Fig 1.9
10. sqrt:- It return the square root of a number.
Syntax:- select sqrt(144);

Fig 1.10
11. tan:- It returns the tangent of a number.
Syntax:- select tan(60);

Fig 1.11
Maharishi Markandeshwar deemed to be university, Mullana, Ambala
Name:- Raunak mishra Roll No :- 11222619
Subject:- Database Management System course code:- BCSE- 510

12. mod:- Returns the remainder of a number divided by another number.


Syntax:- select mod(208,30);

Fig 1.12
13. round:- Rounds a number to a specified number of decimal places.
Syntax:- select round(18.690, 20);

Fig 1.13
14. upper:- convert a string to upper case.
Syntax:- select upper(string);

Fig 1.14
15. abs:- It return the absolute value of a number.
Syntax:- select abs(-75);

Fig 1.15
16. lpad:- Left-pads a string with another string, to a certain length.
Maharishi Markandeshwar deemed to be university, Mullana, Ambala
Name:- Raunak mishra Roll No :- 11222619
Subject:- Database Management System course code:- BCSE- 510

Syntax:- select lpad(colName, number, anyCharacter) from tablename;

Fig 1.16
17. length:- It returns the length of string(in bytes).
Syntax:- select length(string);

Fig 1.17
18. rpad:- Right-pads a string with another string, to a certain length.
Syntax:- select rpad(colName, number, anyCharacter);

Fig 1.18
19. lower:- Convert a string to lower case.
Syntax:- select lower(string);

Fig 1.19
Maharishi Markandeshwar deemed to be university, Mullana, Ambala
Name:- Raunak mishra Roll No :- 11222619
Subject:- Database Management System course code:- BCSE- 510

20. instr:- Returns the position of the first occurrence of a string in another
string.

Syntax:- select instr(colName, character) from tableName;

Fig 1.20
21. ascii :-Return the ASCII value for the specific character.
Syntax:- select asci(string);

Fig 1.21
22. concat:- Adds two or more expressions together.
Syntax:- select concat(string);

Fig 1.22
23. left:- Extracts a number of characters from a string (starting from left).
Syntax:- select left(string, number);

Fig 1.23
Maharishi Markandeshwar deemed to be university, Mullana, Ambala
Name:- Raunak mishra Roll No :- 11222619
Subject:- Database Management System course code:- BCSE- 510

24. right:- Extracts a number of characters from a string (starting from right).
Syntax:- select right(string, number);

Fig 1.24
25. locate:- Returns the position of the first occurrence of a substring in a
string.

Syntax:- select locate(‘kumar’, ‘rohankumar’);

Fig 1.25
26. ltrim:- Removes leading spaces from a string.
Syntax:- select ltrim(‘ Mountains’);

Fig 1.26
27. replace:- Replace all occurrences of a substring within a string, with a new substring.
Syntax:- select replace(string, word to be replaced, replacing word);

Fig 1.27
Maharishi Markandeshwar deemed to be university, Mullana, Ambala
Name:- Raunak mishra Roll No :- 11222619
Subject:- Database Management System course code:- BCSE- 510

28. rtrim:- Remove trailing spaces from a string.


Syntax:- select rtrim(‘Mountain ’);

Fig 1.28
MySQL date functions:-
1.day :- Returns the day of the month for a given date.
Syntax:- select day(“year-month-date);

Fig 1.29
2. curdate:- returns the current date.
Syntax:- select day(curdate());

Fig 1.30
3. datediff:- It returns the number of days between two date values.
Syntax:- select datediff(date1, date2);

Fig 1.31
Maharishi Markandeshwar deemed to be university, Mullana, Ambala
Name:- Raunak mishra Roll No :- 11222619
Subject:- Database Management System course code:- BCSE- 510

4. dayname:- It return the weekday name for a specified day.


Syntax:- select dayname(date);

Fig 1.32
5. dayofweek:- It returns the week day index for a specified date.
Syntax:- select dayofweek(date);

Fig 1.33
6. dayofmonth:- It is used to retrieve the day of the month from the given date.
Syntax:- select dayofmonth(date);

Fig 1.34

You might also like