ITPub博客

首页 > 数据库 > 国内数据库 > 南大通用技术分享:GBase 8a数据库字符串函数—SUBSTRING讲解

南大通用技术分享:GBase 8a数据库字符串函数—SUBSTRING讲解

原创 国内数据库 作者:GBASE南大通用 时间:2026-08-25 16:50:50 0 删除 编辑

南大通用GBase 8a数据库(gbase database)字符串函数简介:

SUBSTRING()

语法格式

SUBSTRING(str,pos) 
SUBSTRING(str,pos,len) 
SUBSTRING (str from pos) 
SUBSTRING (str from pos for len)

函数说明
没有 len 参数的 SUBSTRING()函数从字符串 str 的 pos 位置返回剩余全部子串。

带有 len 参数的 SUBSTRING()函数从字符串 str 的 pos 位置起返回 len 个字符的子 串。

pos 可以是负值,在这种情况下,子串的起始位置是从字符串的尾部向前的 pos 位置。

如果 len 为 0,返回结果为空串。
如果 str 为 NULL,返回结果为 NULL。

示例

示例 1:返回“Quadratically”从第 5 位开始的子串。

gbase> SELECT SUBSTRING('Quadratically',5) FROM dual;
+------------------------------+
| SUBSTRING('Quadratically',5) | 
+------------------------------+
| ratically |
 +------------------------------+1 row in setgbase> SELECT SUBSTRING('Quadratically' from 5);
 +-----------------------------------+
| SUBSTRING('Quadratically' from 5) | 
+-----------------------------------+
| ratically | 
+-----------------------------------+1 row in set

示例 2:返回“Quadratically”从第 5 位开始的 6 个字符。

gbase> SELECT SUBSTRING('Quadratically',5,6) FROM dual;
+--------------------------------+
| SUBSTRING('Quadratically',5,6) | 
+--------------------------------+
| ratica | 
+--------------------------------+1 row in setgbase> SELECT SUBSTRING('Quadratically' from 5 for 6); 
+-----------------------------------------+
| SUBSTRING('Quadratically' from 5 for 6) | 
+-----------------------------------------+
| ratica | 
+-----------------------------------------+1 row in set

示例 3:pos 为“-3”,则返回的子串是“Sakila”尾部的 3 个字符。

gbase> SELECT SUBSTRING('Sakila', -3) FROM dual;
+-------------------------+| SUBSTRING('Sakila', -3) | 
+-------------------------+| ila |
 +-------------------------+1 row in set

示例 4:pos 为“-5”,len 为“3”,则返回的子串为“Sakila”从第 2 位开始的 3 个字符。

gbase> SELECT SUBSTRING('Sakila', -5, 3) FROM dual;
+----------------------------+| SUBSTRING('Sakila', -5, 3) | 
+----------------------------+| aki | 
+----------------------------+1 row in set

示例 5:str 为 NULL 示例以及 len 为 0 的示例。

gbase> SELECT SUBSTRING('Sakila', 0);
+------------------------+
| SUBSTRING('Sakila', 0) | 
+------------------------+
| Sakila | 
+------------------------+1 row in set (Elapsed: 00:00:00.00)gbase> SELECT SUBSTRING('Sakila',0,0);
+-------------------------+
| SUBSTRING('Sakila',0,0) |
+-------------------------+ 
|						| 
+-------------------------+1 row in set (Elapsed: 00:00:00.00)gbase> SELECT SUBSTRING(NULL, 0);
+--------------------+
| SUBSTRING(NULL, 0) |
 +--------------------+
| NULL | 
+--------------------+1 row in set (Elapsed: 00:00:00.00)gbase> SELECT SUBSTRING(NULL,0,0);
+---------------------+
| SUBSTRING(NULL,0,0) | 
+---------------------+
| NULL | 
+---------------------+1 row in set


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69979120/viewspace-3180592/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
GBASE南大通用,致力于成为用户最信赖的数据库产品供应商!

注册时间:2020-07-16

  • 博文量
    1307
  • 访问量
    1279281