MySQL's SQL syntax and common functions have not been sorted out for a long time, and I feel more and more lazy. just recently, there was a MYSQL project (an ORACLE application was migrated to MYSQL) and I have never touched MYSQL before, however, we also know that MYSQL databases are widely used in various personal and business systems, and various technologies are relatively mature. I will summarize some of my learning processes. the content I have designed in this article is not described in too much detail. it is just a simple Getting started manual.
1. data type
MySQL supports all standard SQL numeric data types. These types include strict NUMERIC data types (INTEGER, SMALLINT, DECIMAL, and NUMERIC), and approximate NUMERIC data types (FLOAT, REAL, and double precision ). The keyword INT is the synonym of INTEGER, and the keyword DEC is the synonym of DECIMAL
2 String functions
CHARSET (str) // returns the string character set
CONCAT (string2 [,... ]) // Connection string. Be sure not to keep the ORACLE habit
Mysql> select concat ('A', 'B ');
+ ----------------- +
| Concat ('A', 'B') |
+ ----------------- +
| AB |
+ ----------------- +
1 row in set (0.03 sec)
Mysql> select 'A' | 'B ';
+ ---------- +
| 'A' | 'B' |
+ ---------- +
| 0 |
+ ---------- +
1 row in set, 2 warnings (0.00 sec)
INSTR (string, substring) // returns the position of the first occurrence of the substring in the string. If no position exists, 0 is returned.
LCASE (string2) // converts it to lowercase
LEFT (string2, length) // get the length from the LEFT of string2
LENGTH (string) // string LENGTH
LOAD_FILE (file_name) // read content from the file
LOCATE (substring, string [, start_position])
// Same as INSTR, but the start position can be specified
LPAD (string2, length, pad) // repeat pad to start with string until the string length
Is length
LTRIM (string2) // Remove leading spaces
REPEAT (string2, count) // REPEAT count times
REPLACE (str, search_str, replace_str)
// Replace search_str with replace_str in str
RPAD (string2, length, pad) // use pad after str until length
RTRIM (string2) // remove backend spaces
STRCMP (string1, string2) // compare the size of two strings by character,
SUBSTRING (str, position [, length])
// Start from the position of str and take the length characters
Note: when processing strings in mysql, the Default subscript of the first character is 1, that is, the parameter position must be greater than or equal to 1.
Mysql> select substring ('abcd );
+ ----------------------- +
| Substring ('abcd',) |
+ ----------------------- +
|
+ ----------------------- +
1 row in set (0.06 sec)
Mysql> select substring ('abcd', 1, 2 );
+ ----------------------- +
| Substring ('abcd', 1, 2) |
+ ----------------------- +
| AB |
+ ----------------------- +
1 row in set (0.00 sec)
TRIM ([[BOTH | LEADING | TRAILING] [padding] FROM] string2)
// Remove the specified characters from the specified position
UCASE (string2) // converts to uppercase
RIGHT (string2, length) // gets the last length character of string2
SPACE (count) // Generate count spaces
3 Mathematical functions
ABS (number2) // absolute value BIN (decimal_number) // decimal to binary CEILING (number2) // rounded up to CONV (number2, from_base, to_base) // Convert FLOOR (number2) in hexadecimal notation // round-down the entire FORMAT (number, decimal_places) // retain the number of decimal places HEX (DecimalNumber) // Convert to hexadecimal notation note: HEX () if a string can be passed in, its ASC-11 code is returned. for example, HEX ('def ') returns 4142143 or a decimal integer, returning its hexadecimal encoding, such as HEX (25) returns 19 LEAST (number, number2 [,...]). // Evaluate the minimum MOD (numerator, denominator) // Evaluate the remainder POWER (number, power) // Evaluate the exponent RAND ([seed]) // random number ROUND (number [, decimals]) // rounding, decimals is the number of decimal places]
Note: the return type is not an integer, for example:
(1) the default value is integer.
Mysql> select round (1.23); + ----- + | round (1.23) | + ----- + | 1 | + ----- + 1 row in set (0.00 sec) mysql> select round (1.56); + ----- + | round (1.56) | + ----- + | 2 | + ----- + 1 row in set (0.00 sec)
(2) the number of decimal places can be set to return floating point data.
Mysql> select round (1.567, 2 );
+ ------ +
| Round (1.567, 2) |
+ ------ +
| 1, 1.57 |
+ ------ +
1 row in set (0.00 sec)
SIGN (number2) // return SIGN, positive and negative or 0
SQRT (number2) // Square