Built-Functions in MySqll (Advance Database System)
khurtdhangonzales
14 views
46 slides
Sep 18, 2024
Slide 1 of 46
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
About This Presentation
A report about built-in functions in MySql
Size: 579.37 KB
Language: en
Added: Sep 18, 2024
Slides: 46 pages
Slide Content
ADVANCE DATABASE SYSTEM Functions (Built-In) Gonzales, Khurt Dhan V. Lledo, Denise Claire O. Macellones, Angelo F.
OVERVIEW Numeric functions String functions Date functions Calculating Dates and Times The IFNULL and COALESCE functions IF functions Case operator
What is Built-in Functions?
TYPES OF SQL BUILT-IN FUNCTIONS Numeric functions String functions Date functions
NUMERIC FUNCTIONS
NUMERIC FUNCTIONS ABS ROUND CEIL FLOOR MOD POWER SQRT GREATEST LEAST RAND
ABS SYNTAX: EXAMPLE: SELECT ABS ( number ); SELECT ABS (-15); The ABS() function returns the absolute value of a number.
ROUND SYNTAX: EXAMPLE: SELECT ROUND ( number, decimal, operations ); SELECT ROUND (123.4567, 2 ); The ROUND() function rounds a number to a specified number of decimal places. The ABS() function returns the absolute value of a number.
CEIL SYNTAX: EXAMPLE: SELECT CEIL ( number ); SELECT CEIL (6.2); SELECT CEILING ( number ); SELECT CEILING (6.2); The CEILING() function returns the smallest integer value that is larger than or equal to a number.
FLOOR SYNTAX: EXAMPLE: SELECT FLOOR ( number ); SELECT FLOOR (5.8); The FLOOR() function returns the largest integer value that is smaller than or equal to a number.
MOD SYNTAX: EXAMPLE: SELECT MOD (dividend, divisor); SELECT MOD (10, 3); MOD() is a mathematical function that calculates the remainder of the division of two numbers.
POWER SYNTAX: EXAMPLE: SELECT POWER ( number, power ); SELECT POWER (2, 3); The POWER() function returns the value of a number raised to the power of another number.
SQRT SYNTAX: EXAMPLE: SELECT SQRT ( number ); SELECT SQRT ( 16 ); The SQRT() function returns the square root of a number.
GREATEST SYNTAX: EXAMPLE: SELECT GREATEST (column 1, column 2,...); SELECT GREATEST (10, 20, 5, 30, 15); The GREATEST() it returns the greatest value in a list of expressions
LEAST SYNTAX: EXAMPLE: SELECT LEAST ( column 1, column 2,... ); SELECT LEAST (10, 20, 5, 30, 15); The LEAST() it returns the smallest value in a list of expressions.
RAND SYNTAX: EXAMPLE: SELECT RAND (); SELECT RAND (); The RAND() function returns a random number between 0 (inclusive) and 1 (exclusive).
STRING FUNCTIONS
STRING FUNCTIONS CHAR_LENGTH CONCAT UPPER | UCASE LOWER | LCASE SUBSTRING | SUBSTR TRIM REPLACE REVERSE LEFT | RIGHT
CHAR_LENGTH SYNTAX: EXAMPLE: SELECT CHAR_LENGTH (); SELECT CHAR_LENGTH (“Functions”); The CHAR_LENGTH() function return the length of a string (in characters). Note : This function is equal to the CHARACTER_LENGTH() function.
CONCAT SYNTAX: EXAMPLE: SELECT CONCAT (); SELECT CONCAT (“ Sql ”, “is”, “ fun!”) AS ConcatenatedString ; The CONCAT() function adds two or more strings together.
CONCAT SYNTAX: EXAMPLE: SELECT CONCAT (); SELECT CONCAT (“ Sql ”, “is”, “fun!”) AS ConcatenatedString ; The CONCAT() function adds two or more expressions together.
LENGTH SYNTAX: EXAMPLE: SELECT LENGTH (); SELECT LENGTH (); The LENGTH() is used to find the length of a word.
UPPER | UCASE SYNTAX: EXAMPLE: SELECT UPPER (); SELECT UPPER (); The UPPER() function converts a string to upper-case.
LOWER | LCASE SYNTAX: EXAMPLE: SELECT LOWER (); SELECT LOWER (); The LOWER() function converts a string to lower-case.
SUBSTRING | SUBSTR SYNTAX: EXAMPLE: SELECT SUBSTRING (string, start, length); SELECT SUBSTRING (“Hello, World!”, 1, 4) AS ExtractString ; The SUBSTRING() function extracts some characters from a string.
TRIM SYNTAX: EXAMPLE: SELECT TRIM (); SELECT TRIM (' Hello, World! ') AS TrimmedString ; The TRIM() is used to cut the given symbol from the string
REPLACE SYNTAX: EXAMPLE: SELECT REPLACE (); SELECT REPLACE ("Hello, Chris!", "Chris", "John"); The REPLACE() function replaces all occurrences of a substring within a string, with a new substring.
REVERSE SYNTAX: EXAMPLE: SELECT REVERSE (); SELECT REVERSE (“Hello, everyone”); The REVERSE() function reverses a string and returns the result.
LEFT SYNTAX: EXAMPLE: SELECT LEFT ( string, number_of_char ); SELECT LEFT (“SQL is fun”, 3) AS ExtractString ; The LEFT() function extracts a number of characters from a string (starting from left).
RIGHT SYNTAX: EXAMPLE: SELECT RIGHT ( string, number_of_char ); SELECT RIGHT (“SQL is fun”, 3) AS ExtractString ; The RIGHT() function extracts a number of characters from a string (starting from right).
DATE FUNCTIONS
DATE FUNCTIONS CURRENT_DATE CURRENT_TIME CURRENT_TIMESTAMP
DATE FUNCTIONS CURRENT_DATE Returns current date CURRENT_TIME Returns current time CURRENT_TIMESTAMP Returns current timestamp
CURRENT_DATE / CURDATE() SYNTAX: SELECT CURRENT_DATE (); or SELECT CURDATE (); The CURRENT_DATE() function returns the current date. Note : The date is returned as "YYYY-MM-DD" (string) or as YYYYMMDD (numeric).
SYNTAX: SELECT CURRENT_TIME (); or SELECT CURTIME (); The CURRENT_TIME() function returns the current time. Note : The time is returned as "HH-MM-SS" (string) or as HHMMSS.uuuuuu (numeric). CURRENT_TIME/ CURTIME()
The CURRENT_TIMESTAMP() function returns the current date and time. Note : The date and time is returned as "YYYY-MM-DD HH-MM-SS" (string) or as YYYYMMDDHHMMSS.uuuuuu (numeric). CURRENT_TIMESTAMP SYNTAX: SELECT CURRENT_TIMESTAMP ();
TIMESTAMP 2024-09-17 10:30:00 2024-09-17 10:30:00 DATE TIME
DATE AND TIME FUNCTIONS DATE Extracts the date part from a datetime expression (timestamp) TIME Extracts the time part from a datetime expression (timestamp)
DATE 2024-09-17 2024 17 YEAR DAY 09 MONTH
DATE AND TIME FUNCTIONS Extract the year from date or date or datetime expression YEAR MONTH DAY Extract the month from date or date or datetime expression Extract the day from date or date or datetime expression
TIME 12:00:00 12 00 HOUR SECOND 00 MINUTE
DATE AND TIME FUNCTIONS Extract the hour from time or datetime expression HOUR MINUTE SECOND Extract the minute from time or datetime expression Extract the second from time or datetime expression
CALCULATING DATES AND TIMES
DATE_ADD The DATE_ADD() function adds a time/date interval to a date and then returns the date. SYNTAX: SELECT DATEADD (date, INTERVAL value addunit );
DATE_SUB SYNTAX: SELECT DATE_SUB (date, INTERVAL value interval); The DATE_SUB() function subtracts a time/date interval from a date and then returns the date.
DATEDIFF SYNTAX: SELECT DATEDIFF (date1, date2); The DATEDIFF() function returns the number of days between two date values.