最新下载
热门教程
- 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;
相关文章
- 《无限暖暖》天星之羽获得位置介绍 12-20
- 《流放之路2》重铸台解锁方法介绍 12-20
- 《无限暖暖》瞄准那个亮亮的成就怎么做 12-20
- 《无限暖暖》魔气怪终结者完成方法 12-20
- 《无限暖暖》曙光毛团获得位置介绍 12-20
- 《无限暖暖》日光果获得位置介绍 12-20