最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
mysql sql LENGTH,RIGHT,CHAR_LENGTH字符处理函数
时间:2022-11-14 23:37:44 编辑:袖梨 来源:一聚教程网
mysql教程 sql LENGTH,RIGHT,CHAR_LENGTH字符处理函数
LENGTH(str)
OCTET_LENGTH(str)
CHAR_LENGTH(str)
CHARACTER_LENGTH(str)
返回字符串str的长度。
mysql> select LENGTH('text');
-> 4
mysql> select OCTET_LENGTH('text');
-> 4mysql> SELECT
-> CONCAT(RIGHT(Name, LENGTH(Name) - INSTR(Name, ' ') + 1),
-> ', ', LEFT(Name, INSTR(Name, ' ') - 1))
-> AS StudentName
-> FROM Student
-> ORDER BY StudentName;
+---------------+
| StudentName |
+---------------+
| But, Cory |
| Harvests, JJ |
| Wang, Joe |
+---------------+
3 rows in set (0.04 sec)
*/
RIGHT(str,len)
返回字符串str的最右面len个字符。
mysql> select RIGHT('foobarbar', 4);
-> 'rbar'
该函数是多字节可靠的
/* Prepare the data */
DROP TABLE Student;CREATE TABLE Student (
StudentID INT NOT NULL PRIMARY KEY,
Name VARCHAR(50) NOT NULL
)TYPE = InnoDB;
/* Insert data for testing */
INSERT INTO Student (StudentID,Name) VALUES (1,'Joe Wang');
INSERT INTO Student (StudentID,Name) VALUES (2,'Cory But');
INSERT INTO Student (StudentID,Name) VALUES (3,'JJ Harvests');Select * from StudentExam;
/* Real command */
SELECT
CONCAT(RIGHT(Name, LENGTH(Name) - INSTR(Name, ' ') + 1),
', ', LEFT(Name, INSTR(Name, ' ') - 1))
AS StudentName
FROM Student
ORDER BY StudentName;
注意,对于多字节字符,其CHAR_LENGTH()仅计算一次。
SELECT Name, CHAR_LENGTH(Name) AS CharLength
FROM DVDs
WHERE CHAR_LENGTH(Name)>5
ORDER BY Name;
相关文章
- 人们熟悉的寄居蟹属于以下哪种分类 神奇海洋11月21日答案 11-21
- 第五人格11.22共研服有什么更新 11月22日共研服更新内容介绍 11-21
- 原神恰斯卡怎么培养 11-21
- 无期迷途四星装束是谁 11-21
- 王者荣耀帝丹高中校服怎么获得 11-21
- 光遇姆明季后续版本怎么玩 11-21