Get the App
SLTechnology News&Howtos  ›  Database  › 

Mysql basic character function

Shulou Source: shulou.com Published: 2022-06-01 11:44:17 09月21日 Update

# View the current character set

SHOW VARIABLES LIKE'% char%'

# one-line function

USE myemployees

# character function

SELECT LENGTH ('') # get parameter bytes SELECT CONCAT (last_name,'_',first_name) FROM employees; # string concatenation SELECT UPPER ('aaa'); # convert to uppercase SELECT LOWER (' AAA'); # convert to lowercase

The index position in # mysql starts from 1, and sbstr and substring have the same effect.

SELECT SUBSTR ('Li Moyu fell in love with Lu Zhanyuan', 7); # intercepted Lu Zhanyuan string, all SELECT SUBSTR from 7 to later ('Li Moyu fell in love with Lu Zhanyuan', 1p3); # intercepted Li Moyu, the second number indicates the length SELECT INSTR ('Yang Buxue fell in love with Yin six', 'Yin six') AS out_put # returns the starting index position where the substring first appears in the big string, but does not return 0SELECT TRIM ('Zhang Cuishan') AS out_put; # remove the space SELECT TRIM ('a 'FROM' aaaaa aaa Cui aaaaa mountain aaaaaa') AS out_put; # remove the specified character before and after the removal, and cannot remove the SELECT LPAD ('Huang chivalrous', 10-scene') AS out_put in the middle # fill from the left * until the specified length is 10, and the string exceeds the specified length. The string will be truncated to the specified length SELECT RPAD ('Master Huang', 10 Magi') AS out_put; # filled from the right * until the specified length 10SELECT REPLACE ('Zhang Wuji falls in love with Zhou Zhiruo', 'Zhou Zhiruo', 'Zhao Min') AS out_put; # replaces all Zhou Zhi in the string with Zhao Min, not a

# case: capitalize the last name, lowercase, and then concatenate

SELECT CONCAT (UPPER (last_name),'_', LOWER (first_name)) FROM employees

Tags: Character string length love don't worry Angelo function position hero uppercase lowercase index number metacharacter parameter right character set byte effect number Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Shulou Information Xiaomi MySQL Redmi