Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Mysql basic character function

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

# 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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report