二进制字符串函数和操作符
二进制字符串函数和操作符#
本节描述那些检查和操作类型为bytea数值的函数和操作符。
SQL定义了一些字符串函数, 在这些函数里使用关键字而不是逗号来分隔参数。详情请见下表。一些函数可以通过常用的函数调用语法使用(详见表.其他的二进制字符串函数)。
表.SQL 二进制字符串函数和操作符
函数 |
返回类型 |
描述 |
例子 |
结果 |
---|---|---|---|---|
string || string |
bytea |
字符串连接 |
E’\Oushu’::bytea || E’\047DB’::bytea |
\ \Oushu’DB\000 |
get_bit(string, offset) |
int |
从字符串中提取位 |
get_bit(E’Th\ \000omas’::bytea, 45) |
1 |
get_byte(string, offset) |
int |
从字符串中提取字节 |
get_byte(E’Th\ \000omas’::bytea, 4) |
109 |
octet_length(string) |
int |
二进制字符串的字节数 |
octet_length( E’jo\ \000se’::bytea) |
5 |
position(substring in string) |
int |
特定子字符串的位置 |
position(E’\ \000om’::bytea in E’Th\ \000omas’::bytea) |
3 |
set_bit(string, offset, newvalue) |
bytea |
在字符串中设置位 |
set_bit(E’Th\ \000omas’::bytea, 45, 0) |
Th\000omAs |
set_byte(string, offset, newvalue) |
bytea |
在字符串中设置字节 |
set_byte(E’Th\ \000omas’::bytea, 4, 64) |
Th\000o@as |
substring(string [from int] [for int]) |
bytea |
提取子字符串 |
substring(E’Th\ \000omas’::bytea from 2 for 3) |
h\000o |
trim([both] bytes from string) |
bytea |
从string的开头和结尾删除只包含 bytes中字节的最长字符串 |
trim(E’\ \000’::bytea from E’\ \000Tom\ \000’::bytea) |
Tom |
还有一些可用的二进制字符串处理函数,在下表中列出。其中有一些是在内部使用,用于实现上表列出的SQL标准的字符串函数。
表.其他二进制字符串函数
函数 |
返回类型 |
描述 |
例子 |
结果 |
---|---|---|---|---|
btrim(string bytea, bytes bytea) |
bytea |
从string的开头和结尾删除只包含bytes 中字节的最长的字符串 |
btrim(E’\ \000trim\ \000’::bytea, E’\ \000’::bytea) |
trim |
encode(string bytea, type text) |
text |
把二进制数据编码为文本表现形式。支持的格式:base64, hex, escape。 |
encode(E’123\ \000456’::bytea, ‘escape’) |
123\000456 |
length(string) |
int |
二进制串的长度 |
length(E’jo\ \000se’::bytea) |
5 |
md5(string) |
text |
计算string的MD5散列值,以十六进制方式返回结果。 |
md5(E’Th\ \000omas’::bytea) |
8ab2d3c9689aaf18b4958c334c82d8b1 |