🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
#### SQL SUBSTRING( )函数 SQL 中的 substring 函数是用来抓出一个栏位资料中的其中一部分。这个函数的名称在不同的资料库中不完全一样: 1. MySQL: SUBSTR( ), SUBSTRING( ) 2. Oracle: SUBSTR( ) 3. SQL Server: SUBSTRING( ) 最常用到的方式如下 (在这里我们用 SUBSTR( ) 为例): ~~~ SUBSTR (str, pos) ~~~ 由 `<str>` 中,选出所有从第 `<pos>` 位置开始的字元。请注意,`<pos>` 位置开始于`1`。 ~~~ SUBSTR (str, pos, len) ~~~ 由 `<str>` 中的第 `<pos>` 位置开始,选出接下去的 `<len>` 个字元。 #### 用例:从平台订单号中取出角色ID字段 ![](https://box.kancloud.cn/fdb77e5b6c7344b1519bd66500d4bc91_577x368.png) ~~~ SELECT SUBSTR(`platformOrderId`, 3, 6) AS CharacterId FROM `verify` ~~~ ![](https://box.kancloud.cn/4c2261cc3943724483eadad06084e0c2_194x346.png) * * * * * 来源:https://www.1keydata.com/cn/sql/sql-substring.php