PostgreSQL 字符串操做函數

函數 返回類型 描述 例子 結果
string || string text 字串鏈接 'Post' || 'greSQL' PostgreSQL
bit_length(string) int 字串裏二進制位的個數 bit_length('jose') 32
char_length(string) int 字串中的字符個數 char_length('jose') 4
convert(string using conversion_name) text 使用指定的轉換名字改變編碼。 convert('PostgreSQL' using iso_8859_1_to_utf8) 'PostgreSQL'
lower(string) text 把字串轉化爲小寫 lower('TOM') tom
octet_length(string) int 字串中的字節數 octet_length('jose') 4
overlay(string placing string from int [for int]) text 替換子字串 overlay('Txxxxas' placing 'hom' from 2 for 4) Thomas
position(substring in string) int 指定的子字串的位置 position('om' in 'Thomas') 3
substring(string [from int] [for int]) text 抽取子字串 substring('Thomas' from 2 for 3) hom
substring(string from pattern) text 抽取匹配 POSIX 正則表達式的子字串 substring('Thomas' from '...$') mas
substring(string from pattern for escape) text 抽取匹配SQL正則表達式的子字串 substring('Thomas' from '%#"o_a#"_' for '#') oma
trim([leading | trailing | both] [characters] from string) text 從字串string的開頭/結尾/兩邊/ 刪除只包含characters(缺省是一個空白)的最長的字串 trim(both 'x' from 'xTomxx') Tom
upper(string) text 把字串轉化爲大寫。 upper('tom') TOM
ascii(text) int 參數第一個字符的ASCII碼 ascii('x') 120
btrim(string text [, characters text]) text 從string開頭和結尾刪除只包含在characters裏(缺省是空白)的字符的最長字串 btrim('xyxtrimyyx','xy') trim
chr(int) text 給出ASCII碼的字符 chr(65) A
convert(string text, [src_encoding name,] dest_encoding name) text 把字串轉換爲dest_encoding convert( 'text_in_utf8', 'UTF8', 'LATIN1') 以ISO 8859-1編碼表示的text_in_utf8
initcap(text) text 把每一個單詞的第一個子母轉爲大寫,其它的保留小寫。單詞是一系列字母數字組成的字符,用非字母數字分隔。 initcap('hi thomas') Hi Thomas
length(string text) int string中字符的數目 length('jose') 4
lpad(string text, length int [, fill text]) text 經過填充字符fill(缺省時爲空白),把string填充爲長度length。 若是string已經比length長則將其截斷(在右邊)。 lpad('hi', 5, 'xy') xyxhi
ltrim(string text [, characters text]) text 從字串string的開頭刪除只包含characters(缺省是一個空白)的最長的字串。 ltrim('zzzytrim','xyz') trim
md5(string text) text 計算給出string的MD5散列,以十六進制返回結果。 md5('abc')  
repeat(string text, number int) text 重複string number次。 repeat('Pg', 4) PgPgPgPg
replace(string text, from text, to text) text 把字串string裏出現地全部子字串from替換成子字串to。 replace('abcdefabcdef', 'cd', 'XX') abXXefabXXef
rpad(string text, length int [, fill text]) text 經過填充字符fill(缺省時爲空白),把string填充爲長度length。若是string已經比length長則將其截斷。 rpad('hi', 5, 'xy') hixyx
rtrim(string text [, character text]) text 從字串string的結尾刪除只包含character(缺省是個空白)的最長的字 rtrim('trimxxxx','x') trim
split_part(string text, delimiter text, field int) text 根據delimiter分隔string返回生成的第field個子字串(1 Base)。 split_part('abc~@~def~@~ghi', '~@~ ', 2) def
strpos(string, substring) text 聲明的子字串的位置。 strpos('high','ig') 2
substr(string, from [, count]) text 抽取子字串。 substr('alphabet', 3, 2) ph
to_ascii(text [, encoding]) text 把text從其它編碼轉換爲ASCII。 to_ascii('Karel') Karel
to_hex(number int/bigint) text 把number轉換成其對應地十六進制表現形式。 to_hex(9223372036854775807) 7fffffffffffffff
translate(string text, from text, to text) text 把在string中包含的任何匹配from中的字符的字符轉化爲對應的在to中的字符。 translate('12345', '14', 'ax') a23x5
相關文章
相關標籤/搜索