Section 8 - character function of the common functions

Common Functions

① Function: The method is similar to Java, a language is encapsulated in a set of logical method body, the external exposure method name.

. ② benefits: hide implementation details; 2 improves the reusability of the code;.

③ call: select function name (argument list) table [from]

④ Category: 1. one-way function, such as concat, length, ifnull the like;

                  2. The packet function; do use statistics, also known as statistical functions, aggregate functions, function group;

 

A character function

① length byte parameter acquired;

SELECT length ( ' John ' ); # 4 results
SELECT length ( ' Chi Master ' ); # result. 9; the UTF8 one letter occupies one byte, a character occupies . 3 bytes

 

② concat string concatenation

select concat(last_name, '_', first_name) 姓名 from employees;

 

③ upper,lower

SELECT Upper ( ' Jhon ' ); variant # uppercase letters
 SELECT Lower ( ' JHON ' ); # letters to lower case

Example ② and ③ in combination:

the SELECT concat (Upper (last_name), Lower (first_name) name from the Employees; # change the name in uppercase, lowercase name change, then splicing

 

④ substr / substring; interception of characters, there are two usage

Use a: 

SELECT substr ( ' Limo Chou Lu Chin element in love ' , 7 ); # Results are shown as 'Fair Lu Yuan'; This usage represents all the characters taken from the back of the specified index;

Usage of Two:

SELECT substr ( ' Limo Chou Lu Chin element in love ' , 1 , 3 ); # Results are shown as 'Limo Chou'; represents a character from the character length intercepts this usage index

Example: Name the first character in uppercase, lowercase other characters, and then use _ stitching, displayed

select concat(upper(substr(last_name,1,1)), '_', lower(substr(last_name,2)))  out_put from employees;

 

⑤ instr substring sequence number returns the index of the first occurrence, returns 0 if no

Example:

SELECT InStr ( ' Yang Buhui love with six Yin Xia ' , ' Yin six Man ' ) AS out_put; results are shown as # 7;

 

⑥ trim function

trim () remove spaces on either side of the string;

SELECT TRIM ( '          Cuishan            ' ) AS out_put; # Results are shown as 'Cuishan';

TRIM ( 'character 1', from 'string 2')  , respectively, deletes a specified character string 1 from both sides ;

Example:

SELECT TRIM ( ' A ' , from  ' AAAA sheets aaa Greenfield AAAA ' ) AS out_put; # Results are shown as 'aaa Greenfield sheets';

 

⑦ LPAD achieve left filled with the specified character specified length;

SELECT LPAD ( ' Yin Susu ' , 10 , ' * ' ) the AS out_put; # Results are shown as "******* Yin Susu '

⑧ RPAD achieve the right filled with the specified character specified length;

SELECT RPAD ( ' Yin Susu ' , 12 is , ' ab & ' ) out_put the AS; results are shown as 'Yin Susu ababababa'

 

⑨ replace replace

SELECT Replace ( ' zhangwuji Zhou Zhiruo in love ' , ' Zhou Zhiruo ' , ' Zhao ' ) out_put the AS; # result is 'love with Zhao zhangwuji'

 

Guess you like

Origin www.cnblogs.com/Jasmine6-Lee/p/12625513.html