单行字符串函数用于操作字符串数据,他们大多数有一个或多个参数,其中绝大多数返回字符串。
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()
c1为字符串,返回c1的长度,如果c1为null,那么将返回null值。
select length('ipso facto') ergo from dualergo10
lengthb()
|
与length()一样,返回字节。
返回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相似
把c1中最右边的字符去掉,使其第后一个字符不在c2中,如果没有c2,那么c1就不会改变。
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是以字节计算。
返回与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
|
|