- SUBSTRING 函数用于截取指定长度的字符串,并将截取的字符串返回
SUBTRING(expression,start,length);
SELECT SUBSTRING('aabbcc',3,2);
SELECT SUBSTRING('aabbcc',3,LEN('aabbcc'));
SELECT SUBSTRING('aabbcc',3,100); -- 截取超过字符串长度不会报错,返回从截取起始位置到最后的字符串
image.png
SELECT * FROM Subject WHERE ID=4;
SELECT SUBSTRING(Description,3,6) AS New_Description FROM Subject WHERE ID=4;
SELECT SUBSTRING(Description,3,100) AS New_Description FROM Subject WHERE ID=4;
image.png
- SUBSRTING 与 STUFF 对比
同样都是对字符串进行截取操作,SUBSTRING 是返回的结果是被截掉的部分,STUFF 返回的结果是截取后剩余的其他部分
网友评论