Previous: [MySQL Must Know and Know (7)] [Create Calculated Field]
+++++++++++++Start line++++++++++++++++
Article Directory
1. Function
Like most other computer languages, SQL supports the use of functions to process data. Functions are generally executed on data, which provides convenience for data conversion and processing.
Functions are not as portable as SQL
Code that can run on multiple systems is called portable. Relatively speaking, most SQL statements are portable, and there are differences between SQL implementations, which are usually not so difficult to deal with. The portability of functions is not strong. Almost every major DBMS implementation supports functions not supported by other implementations.
Second, use the function
1. Text functions for processing text strings
2. Numerical functions for performing arithmetic operations on numerical functions
3. Date and time functions for processing date and time values and extracting specific components from these values
4. Return to DBMS System function of the special information being used
2.1 Text function
Upper() function
mysql> SELECT vend_name, Upper(vend_name)AS vend_name_upcase
-> FROM vendors
-> ORDER BY vend_name;
SOUNDEX() is an algorithm that converts any text string into an alphanumeric mode describing its phonetic representation
mysql> SELECT cust_name, cust_contact
-> FROM customers
-> WHERE cust_contact = 'Y. Lie'; Empty set (0.02 sec)
mysql> SELECT cust_name, cust_contact
-> FROM customers
-> WHERE Soundex(cust_contact) = Soundex('Y Lie');
2.2 Date and time processing functions
mysql> SELECT cust_id, order_num
-> FROM orders
-> WHERE order_date = '2005-09-01';
If you want a date, use Date()
If all you want is the date, it is a good habit to use Date()
mysql> SELECT cust_id, order_num
-> FROM orders
-> WHERE Date(order_date) BETWEEN '2005-09-01' AND '2005-09-30';
mysql> SELECT cust_id, order_num
-> FROM orders
-> WHERE Year(order_date) = 2005 AND Month(order_date) = 9;
2.3 Numerical processing functions
+++++++++++++End line++++++++++++++++