Page 174 - Informatics_Practices_Fliipbook_Class12
P. 174
Example:
SELECT INSTR("hello world", "world");
Output: 7
In the above example, the INSTR() function returns value 7 as the position of the substring "world" within the
string "hello world" is at position 7.
8. LTRIM()
The LTRIM() function removes leading spaces (or specified characters) from a string.
Example:
SELECT LTRIM(" MySQL");
Output: "MySQL"
In the above example, the LTRIM() function removes the leading spaces from the string " MySQL".
9. RTRIM()
The RTRIM() function removes trailing spaces (or specified characters) from a string.
Example:
SELECT RTRIM("MySQL ");
Output: "MySQL"
In the above example, the RTRIM() function removes the trailing spaces from the string "MySQL ".
10. TRIM()
The TRIM() function removes leading and trailing spaces (or specified characters) from a string.
Example:
SELECT TRIM(" MySQL ");
Output: "MySQL"
In the above example, the TRIM() function removes both the leading and trailing spaces from the string
" MySQL ".
4.4.18 Date Functions
Date functions enable us to deal with date and time information. Following are some commonly used MySQL date
functions:
1. NOW()
The NOW() function returns the current date and time.
Example:
SELECT NOW();
Output: "2023-06-04 15:30:00"
In the above example, the NOW() function returns the current date and time.
2. DATE()
The DATE() function extracts the date portion from a given date or datetime value.
Example:
SELECT DATE('2023-06-04 15:30:00');
Output: "2023-06-04"
In the above example, the DATE() function extracts the date portion from the datetime value '2023-06-04
15:30:00'.
160 Touchpad Informatics Practices-XII

