MySQL中substr()函數(shù)的使用示例
截取函數(shù)substr()方法以及參數(shù)詳解
1、substr(str, position) 從position截取到字符串末尾
str可以是字符串、函數(shù)、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的操作對比可以發(fā)現(xiàn)只是把括號中的逗號換成from關(guān)鍵字
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可以是字符串、函數(shù)、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的操作對比可以發(fā)現(xiàn)只是把括號中的第一個逗號換成from關(guān)鍵字,
第二個逗號換成了for關(guān)鍵字
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);
到此這篇關(guān)于MySQL中substr()函數(shù)的使用示例的文章就介紹到這了,更多相關(guān)MySQL substr()函數(shù)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
刪除mysql數(shù)據(jù)庫中的重復(fù)數(shù)據(jù)記錄
mysql中select distinct * from text不能顯示不重復(fù)的記錄,而是直接全部顯示2008-06-06
關(guān)于MySQL innodb_autoinc_lock_mode介紹
下面小編就為大家?guī)硪黄P(guān)于MySQL innodb_autoinc_lock_mode介紹。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-03-03
Trae MySQL MCP 連接失敗(Fail to start)的
本文詳細(xì)介紹了使用Trae工具遠(yuǎn)程訪問內(nèi)網(wǎng)MySQL數(shù)據(jù)庫時遇到的啟動和認(rèn)證兼容問題,并通過本地命令映射和環(huán)境變量注入的方式成功解決,具有一定的參考價值,感興趣的可以了解一下2026-01-01
SQLyog錯誤號碼MySQL?plugin?caching_sha2_password?could?not?
這篇文章主要介紹了SQLyog錯誤號碼?plugin?caching_sha2_password?could?not?be?loaded的解決方法,需要的朋友可以參考下2023-06-06
MySQL如何追蹤數(shù)據(jù)庫中對特定表的更新操作
這篇文章主要為大家詳細(xì)介紹了五種不同的方法 來追蹤 MySQL 數(shù)據(jù)庫中對特定表(如 statistics_test)的更新操作,并提供詳細(xì)的代碼示例和適用場景分析,希望對大家有所幫助2025-06-06
mysql8.0使用PXC實現(xiàn)高可用的示例(Rocky8.0環(huán)境)
本文主要介紹了在Rocky8.0環(huán)境下搭建MySQL8.0的Percona XtraDB Cluster(PXC)集群,,可以實現(xiàn)數(shù)據(jù)實時同步、讀寫分離和高可用性,具有一定的參考價值,感興趣的可以了解一下2025-02-02
避免MySQL中的隱式轉(zhuǎn)換的方法小結(jié)
在 MySQL 中,隱式轉(zhuǎn)換可能導(dǎo)致索引失效、結(jié)果不符合預(yù)期或性能問題,以下是避免隱式轉(zhuǎn)換的具體方法,從表設(shè)計、查詢編寫到配置優(yōu)化,逐步減少隱式轉(zhuǎn)換的發(fā)生,具體操作過程跟隨小編一起看看吧2025-04-04

