GBase 8c
其他
文章

GBase 8c数据类型——字符串操作符

发表于2023-12-06 14:42:26151次浏览0个评论

字符串操作符
 

SQL定义了一些字符串函数,在这些函数里使用关键字而不是逗号来分隔参数。

l octet_length(string)

描述:二进制字符串中的字节数。返回值类型:int

示例:

postgres=# SELECT octet_length(E'jo\\000se'::bytea) AS RESULT;

result

--------

      5

(1 row)

l overlay(string placing string from int [for int])

描述:替换子串。返回值类型:bytea

示例:

postgres=# SELECT overlay(E'Th\\000omas'::bytea placing E'\\002\\003'::bytea from 2 for 3) AS RESULT;

result

----------------

\x5402036d6173

(1 row)

l position(substring in string) 描述:特定子字符串的位置。返回值类型:int

示例:

postgres=# SELECT position(E'\\000om'::bytea in E'Th\\000omas'::bytea) AS RESULT;

result

--------

3

(1 row)

l substring(string [from int] [for int])

描述:截取子串。返回值类型:bytea

示例:

postgres=# SELECT substring(E'Th\\000omas'::bytea from 2 for 3) AS RESULT;

 result

----------

\x68006f

(1 row)

l substr(string, from int [, for int])

描述:截取子串。返回值类型:bytea

示例:

postgres=# select substr(E'Th\\000omas'::bytea,2, 3) as result;

result

----------

\x68006f

(1 row)

l trim([both] bytes from string)

描述:从string的开头和结尾删除只包含bytes中字节的最长字符串。返回值类型:bytea

示例:

postgres=# SELECT trim(E'\\000'::bytea from E'\\000Tom\\000'::bytea) AS RESULT;

result

----------

\x546f6d

(1 row)

评论

登录后才可以发表评论