oracle字符串函数

<!-- /* Font Definitions */ @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:1; mso-generic-font-family:roman; mso-font-format:other; mso-font-pitch:variable; mso-font-signature:0 0 0 0 0 0;} @font-face {font-family:Verdana; panose-1:2 11 6 4 3 5 4 4 2 4; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:536871559 0 0 0 415 0;} @font-face {font-family:"/@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:12.0pt; font-family:"Times New Roman","serif"; mso-fareast-font-family:宋体; mso-font-kerning:1.0pt;} tt {mso-style-unhide:no; mso-ansi-font-size:12.0pt; mso-bidi-font-size:12.0pt; font-family:宋体; mso-ascii-font-family:宋体; mso-fareast-font-family:宋体; mso-hansi-font-family:宋体; mso-bidi-font-family:宋体;} span.optional {mso-style-name:optional; mso-style-unhide:no;} span.acronym {mso-style-name:acronym; mso-style-unhide:no;} .MsoChpDefault {mso-style-type:export-only; mso-default-props:yes; font-size:10.0pt; mso-ansi-font-size:10.0pt; mso-bidi-font-size:10.0pt; mso-ascii-font-family:"Times New Roman"; mso-fareast-font-family:宋体; mso-hansi-font-family:"Times New Roman"; mso-font-kerning:0pt;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.Section1 {page:Section1;} -->

函数

返回类型

描述

例子

结果

string || string

text

字串连接

'Post' || 'greSQL'

PostgreSQL

bit_length( string )

integer

字串里二进制位的个数

bit_length('jose')

32

char_length( string ) character_length( string )

integer

字串中的字符个数

char_length('jose')

4

convert( string using conversion_name )

text

使用指定的转换名字改变编码。转换可以通过 CREATE CONVERSION 定义。当然系统里有一些预定义的转换名字。参阅 Table 9-8 获取可用的转换名。

convert('PostgreSQL'
 using
iso_8859_1_to_utf_8)

Unicode (UTF-8) 编码的 'PostgreSQL'

lower( string )

text

把字串转化为小写

lower('TOM')

tom

octet_length( string )

integer

字串中的字节数

octet_length('jose')

4

position( substring in string )

integer

声明的子字串的位置

position('om' in 'Thomas')

3

overlay( string placing string from integer [ for integer ])

text

替换子字串

overlay('Txxxxas' placing 'hom' from 2 for 4)

Thomas

position( substring in string )

integer

指定的子字串的位置

position('om' in 'Thomas')

3

substring ( string [from integer ] [for integer ])

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)

integer

参数第一
个字符的 ASCII

ascii('x')

120

btrim
(string text, characters text)

text

string
开头和结尾删除 只包含在 characters 里的字符的最长字串。

btrim
('xyxtrimyyx','xy')

trim

chr(integer)

text

给出 ASCII 码的字符

chr(65)

A

convert(string text, [src_encoding name,] dest_encoding name)

text

把字串转换为 dest_encoding . 原来的编码是用 src_encoding 声明的 . 如果省略了 src_encoding , 则假设为数据库编码 .

convert(
'text_in_unicode',
 'UNICODE',
'LATIN1')

ISO
8859-1
编码表示的 text_in
_unicode

decode(string text, type text)

bytea

把早先用 encode 编码的,存放在 string 里面的二进制数据解码。 参数类型和 encode 一样。

decode('MTIzAAE=',
 'base64')

123/000/001

encode(data bytea, type text)

text

把二进制数据编码为只包含 ASCII 形式的数据。 支持的类型有 base64 hex escape

encode('123//000
//001', 'base64')

MTIzAAE=

initcap(text)

text

把每个单词(空白分隔)的第一个子母转为大写

initcap('hi
thomas')

Hi Thomas

length(string )

integer

字串中字符的数目

length('jose')

4

lpad(string text, length integer [, 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

计算给出字串的 MD5 散列,以十六进制返回结果。

md5('abc')

90015098
3cd24
fb0d69
63f7d2
8e17f72

pg_client_encoding()

name

当前客户端编码名称。

pg_client_
encoding()

SQL_ASCII

quote_ident(string text)

text

返回给出字串的一个适用于在 SQL 语句字串里当作标识符引起使用的形式。 只有在必要的时候才会添加引号(也就是说,如果字串包含非标识符字符或者会 转换大小写的字符)。 嵌入的引号被恰当地写了双份。

quote_ident('Foo')

"Foo"

quote_literal(string text)

text

返回给出字串的一个适用于在 SQL 语句字串里当作文本使用的形式。 嵌入的引号和反斜杠被恰当地写了双份。

quote_literal
('O/'Reilly')

'O''Reilly'

repeat(text, integer)

text

重复 text 一定次数。

repeat('Pg', 4)

PgPgPgPg

replace(string text, from text, to text)

text

把字串 string 里出现地所有子字串 from 替换成子字串 to

replace
('abcdefabcdef',
 'cd', 'XX')

abXXef
abXXef

rpad(string text, length integer [, 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 integer)

text

根据 delimiter 分隔 string 返回生成的第 field 个子字串(一为基)。

split_part
('abc~@~def
~@~ghi','~@~',2
)

def

strpos(string , substring )

text

声明的子字串的位置。(和 position(substring in string 一样) ,不过要注意参数顺序 是相反的)

strpos
('high','ig')

2

substr(string , from [, count ])

text

抽取子字串。(和 substring(string from from for count ) 一样)

substr('alphabet',
3, 2)

ph

to_ascii
(text [, encoding ])

text

把文本从其它编码转换为 ASCII [a]

to_ascii('Karel')

Karel

to_hex(number integer 或者 bigint)

text

number 转换成其对应地十六进制表现形式。

to_hex(922337203
6854775807)

7fffffff
ffffffff

translate(string text, from text, to text)

text

把在 string 中包含的任何匹配 from 中的字符的字符转化为对应的 to 中的字符。

translate('12345',
 '14', 'ax')

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值