?
This document uses PHP Chinese website manual Release
本節(jié)描述那些檢查和操作類(lèi)型為bytea數(shù)值的函數(shù)和操作符。
SQL定義了一些有特殊語(yǔ)法的字符串函數(shù),在這些函數(shù)里使用特殊關(guān)鍵字而不是逗號(hào)來(lái)分隔 參數(shù)。詳情參閱Table 9-8。PostgreSQL也提供了一些 使用常用語(yǔ)法進(jìn)行函數(shù)調(diào)用的函數(shù)版本(參閱Table 9-9)。
Table 9-8. SQL二進(jìn)制字符串函數(shù)和操作符
函數(shù) | 返回類(lèi)型 | 描述 | 示例 | 結(jié)果 |
---|---|---|---|---|
string|| string | bytea | 字符串連接 | E'\\\\Post'::bytea || E'\\047gres\\000'::bytea | \\Post'gres\000 |
octet_length(string) |
int | 二進(jìn)制字符串的字節(jié)數(shù) | octet_length(E'jo\\000se'::bytea) | 5 |
overlay(stringplacingstringfromint[forint]) |
bytea | 替換子串 | overlay(E'Th\\000omas'::bytea placing E'\\002\\003'::bytea from 2 for 3) | T\\002\\003mas |
position(substringinstring) |
int | 指定子串的位置 | position(E'\\000om'::bytea in E'Th\\000omas'::bytea) | 3 |
substring(string[fromint][forint]) |
bytea | 截取子串 | substring(E'Th\\000omas'::bytea from 2 for 3) | h\000o |
trim([both]
bytesfrom
string)
|
bytea | 從string的開(kāi)頭和結(jié)尾刪除只包含bytes中字節(jié)的最長(zhǎng)字符串 | trim(E'\\000'::bytea from E'\\000Tom\\000'::bytea) | Tom |
還有一些二進(jìn)制字符串處理函數(shù)可以使用,在Table 9-9列出。 其中有一些是在內(nèi)部使用,用于實(shí)現(xiàn)Table 9-8列出的SQL標(biāo)準(zhǔn)的字符串函數(shù)。
Table 9-9. 其它二進(jìn)制字符串函數(shù)
函數(shù) | 返回類(lèi)型 | 描述 | 示例 | 結(jié)果 |
---|---|---|---|---|
btrim(string
bytea,bytesbytea) |
bytea | 從string的開(kāi)頭和結(jié)尾刪除只包含bytes中字節(jié)的最長(zhǎng)字符串 | btrim(E'\\000trim\\000'::bytea, E'\\000'::bytea) | trim |
decode(stringtext,
typetext)
|
bytea | 將之前用encode 編碼的結(jié)果string解碼為二進(jìn)制字符串。參數(shù)類(lèi)型和encode 相同。
|
decode(E'123\\000456', 'escape') | 123\000456 |
encode(stringbytea,
typetext)
|
text | 把二進(jìn)制字符串編碼為ASCII僅表現(xiàn)形式。支持類(lèi)型有:base64,hex,escape。 | encode(E'123\\000456'::bytea, 'escape') | 123\000456 |
get_bit(string,offset)
|
int | 從字符串中提取位 | get_bit(E'Th\\000omas'::bytea, 45) | 1 |
get_byte(string,offset)
|
int | 從字符串中提取字節(jié) | get_byte(E'Th\\000omas'::bytea, 4) | 109 |
length(string) |
int | 二進(jìn)制字符串的長(zhǎng)度 | length(E'jo\\000se'::bytea) | 5 |
md5(string) |
text | 計(jì)算string的MD5散列值,以十六進(jìn)制方式返回結(jié)果。 | md5(E'Th\\000omas'::bytea) | 8ab2d3c9689aaf18 b4958c334c82d8b1 |
set_bit(string,
offset,newvalue)
|
bytea | 設(shè)置字符串中的位 | set_bit(E'Th\\000omas'::bytea, 45, 0) | Th\000omAs |
set_byte(string,
offset,newvalue)
|
bytea | 設(shè)置字符串中的字節(jié) | set_byte(E'Th\\000omas'::bytea, 4, 64) | Th\000o@as |
get_byte
andset_byte
字節(jié)數(shù) 以二進(jìn)制字符串的第一個(gè)字節(jié)為0字節(jié)。
get_bit
andset_bit
位數(shù)每個(gè)字節(jié)的右邊位數(shù);例如 位0 至少在第一個(gè)字節(jié), 位15最多為第二個(gè)字節(jié)位.