MySQL中substr()函数的使用示例
截取函数substr()方法以及参数详解
1、substr(str, position) 从position截取到字符串末尾
str可以是字符串、函数、SQL查询语句
position代表起始位置,索引位置从1开始
select substr(now(), 6);
select substr('2023-10-25', 6);
select substr((select fieldName from tableName where condition), 1);
2、substr(str from position) 从position截取到字符串末尾
和1的操作类似,和上面1的操作对比可以发现只是把括号中的逗号换成from关键字
select substr(now() from 6);
select substr('2023-10-25' from 6);
select substr((select fieldName from tableName where condition) from 1);

3、substr(str, position, length) 从position截取长度为length的字符串
str可以是字符串、函数、SQL查询语句
position代表起始位置
length代表截取的字符串长度
select substr(now(), 1, 4);
select substr('2024-01-01', 1, 4);
select substr((select fieldName from tableName where condition), 1, 4);
4、substr(str from position for length) 从position截取长度为length的字符串
和3的操作类似,和上面3的操作对比可以发现只是把括号中的第一个逗号换成from关键字,
第二个逗号换成了for关键字
select substr(now() from 6 for 5);
select substr('2023-10-01' from 6 for 5);
select substr((select fieldName from tableName where condition) from 6 for 5);
到此这篇关于MySQL中substr()函数的使用示例的文章就介绍到这了,更多相关MySQL substr()函数内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
MySQL数据库char与varchar的区别分析及使用建议
本文主要介绍了mysql中VARCHAR与CHAR字符型数据的差异以及这两种字符型数据在项目中的使用建议,真心不错。值得一看。小编有种受益匪浅的感觉。2014-09-09
Window 下安装Mysql5.7.17 及设置编码为utf8的方法
这篇文章主要介绍了Window 下安装Mysql5.7.17 及设置编码为utf8的方法,非常不错,具有参考借鉴价值,需要的朋友可以参考下2017-03-03
实操MySQL+PostgreSQL批量插入更新insertOrUpdate
这篇文章主要介绍了MYsql和PostgreSQL优势对比以及如何实现MySQL + PostgreSQL批量插入更新insertOrUpdate,附含详细的InserOrupdate代码实例,需要的朋友可以参考下2021-08-08


最新评论