11/15: MySQL > Functions in SQL Expressions
Category: Study
Posted by: hajime osako
IN() always returns NULL when used to test NULL, even if NULL is included in the list.
IF() and CASE as used in expressions have somewhat different syntax than the IF and CASE statements such can be used within compound statements.
For approximate values, ROUND() uses the rounding method provided in the C library.
SELECT ROUND(11.5), ROUND(-11.5); <--- returns 12 and -12
SELECT ROUND(1.15E1), ROUND(-1.15E1); <--- returns 11 and -11
FLOOR() returns the largest integer not greater than its argument.
SELECT FLOOR(14.7), FLLOR(-14.7); <--- returns 14 and -15
The LENGTH() and CHAR_LENGTH() functions determine string lengths in byte and character units, respectively.
The CONCAT() returns NULL if any of its arguments are NULL, however CONCAT_WS() ignores NULL values.
The STRCMP() function compares two strings and returns -1, 0, or 1.
MySQL encription functions:
PASSWORD() (one-way)
ENCODE() and DECODE()
DES_ENCRYPTY() and DES_DECRYPT()
AES_ENCRYPT() and AES_DECRYPT()
MAKEDATE() takes two arguments year and day of the year.
MAKETIME() produces a time from hour, minute, and secound arguments.
To determine the current date or time, CURRENT_DATE, CURRENT_TIME, CURRENT_TIMESTAMP, or NOW().
MySQL disallows a double dash (--) without a space as comment.
/*! */ is not a comment in MySQL.
CREATE TABLE t (i INT) /*! ENGINE = MEMORY */
SHOW /*!50002 FULL */ TABLES; <-- If MySQL is 5.0.2 or newer.
IF() and CASE as used in expressions have somewhat different syntax than the IF and CASE statements such can be used within compound statements.
For approximate values, ROUND() uses the rounding method provided in the C library.
SELECT ROUND(11.5), ROUND(-11.5); <--- returns 12 and -12
SELECT ROUND(1.15E1), ROUND(-1.15E1); <--- returns 11 and -11
FLOOR() returns the largest integer not greater than its argument.
SELECT FLOOR(14.7), FLLOR(-14.7); <--- returns 14 and -15
The LENGTH() and CHAR_LENGTH() functions determine string lengths in byte and character units, respectively.
The CONCAT() returns NULL if any of its arguments are NULL, however CONCAT_WS() ignores NULL values.
The STRCMP() function compares two strings and returns -1, 0, or 1.
MySQL encription functions:
PASSWORD() (one-way)
ENCODE() and DECODE()
DES_ENCRYPTY() and DES_DECRYPT()
AES_ENCRYPT() and AES_DECRYPT()
MAKEDATE() takes two arguments year and day of the year.
MAKETIME() produces a time from hour, minute, and secound arguments.
To determine the current date or time, CURRENT_DATE, CURRENT_TIME, CURRENT_TIMESTAMP, or NOW().
MySQL disallows a double dash (--) without a space as comment.
/*! */ is not a comment in MySQL.
CREATE TABLE t (i INT) /*! ENGINE = MEMORY */
SHOW /*!50002 FULL */ TABLES; <-- If MySQL is 5.0.2 or newer.