Oracle数据库中单行字符串函数简介

王朝oracle·作者佚名  2008-05-31
窄屏简体版  字體: |||超大  

单行字符串函数用于操作字符串数据,他们大多数有一个或多个参数,其中绝大多数返回字符串。

ascii()

c1是一字符串,返回c1第一个字母的ascii码,他的逆函数是chr()

select ascii(''a'') big_a,ascii(''z'') big_z from empbig_a big_z65 122

chr(<i>)[nchar_cs]

i是一个数字,函数返回十进制表示的字符

select chr(65),chr(122),chr(223) from empchr65 chr122 chr223a z b

concat(,)

c1,c2均为字符串,函数将c2连接到c1的后面,假如c1为null,将返回c2.假如c2为null,则返回c1,假如c1、c2都为null,则返回null。他和操作符返回的结果相同

select concat(''slobo '',''svoboda'')

username from dualusernameslobo syoboda

initcap()

c1为一字符串。函数将每个单词的第一个字母大写其它字母小写返回。单词由空格,控制字符,标点符号限制。

select initcap(''veni,vedi,vici'') ceasar

from dualceasarveni,vedi,vici

instr(,[,<i>[,]])

c1,c2均为字符串,i,j为整数。函数返回c2在c1中第j次出现的位置,搜索从c1的第i个字符开始。当没有发现需要的字符时返回0,假如i为负数,那么搜索将从右到左进行,但是位置的计算还是从左到右,i和j的缺省值为1.

select instr(''mississippi'',''i'',3,3)

from dualinstr(''mississippi'',''i'',3,3)

11select instr(''mississippi'',''i'',-2,3)

from dualinstr(''mississippi'',''i'',3,3)2

instrb(,[,i[,j])

与instr()函数一样,只是他返回的是字节,对于单字节instrb()等于instr()

length()

c1为字符串,返回c1的长度,假如c1为null,那么将返回null值。

select length(''ipso facto'') ergo from dualergo10

lengthb()

与length()一样,返回字节。

lower()

返回c的小写字符,经常出现在where子串中

select lower(colorname) from

itemdetail where lower(colorname)

like ''%white%''colornamewinterwhite

lpad(,[,])

c1,c2均为字符串,i为整数。在c1的左侧用c2字符串补足致长度i,可多次重复,假如i小于c1的长度,那么只返回i那么长的c1字符,其他的将被截去。c2的缺省值为单空格,参见rpad。

select lpad(answer,7,'''') padded,

answer unpadded from question;

padded unpadded yes yesno nomaybe maybe

ltrim(,)

把c1中最左边的字符去掉,使其第一个字符不在c2中,假如没有c2,那么c1就不会改变。

select ltrim(''mississippi'',''mis'')

from dualltrppi

rpad(,[,])

在c1的右侧用c2字符串补足致长度i,可多次重复,假如i小于c1的长度,那么只返回i那么长的c1字符,其他的将被截去。c2的缺省值为单空格,其他与lpad相似

rtrim(,)

把c1中最右边的字符去掉,使其第后一个字符不在c2中,假如没有c2,那么c1就不会改变。

replace(,[,])

c1,c2,c3都是字符串,函数用c3代替出现在c1中的c2后返回。

select replace(''uptown'',''up'',''down'')

from dualreplacedowntown

stbstr(,[,])

c1为一字符串,i,j为整数,从c1的第i位开始返回长度为j的子字符串,假如j为空,则直到串的尾部。

select substr(''message'',1,4) from dualsubsmess

substrb(,[,])

与substr大致相同,只是i,j是以字节计算。

soundex()

返回与c1发音相似的词

select soundex(''dawes'')

dawes soundex(''daws'') daws,

soundex(''dawson'') from dualdawes

daws dawsond200 d200 d250

translate(,,)

将c1中与c2相同的字符以c3代替

select translate(''fumble'',''uf'',''ar'')

test from dualtextramble

trim([[]] from c3)

将c3串中的第一个,最后一个,或者都删除。

select trim('' space padded '') trim from dual

trimspace padded

upper()

返回c1的大写,常出现where子串中

select name from dual where upper(name) like ''ki%''nameking

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航