oracle字符串函数收藏

 

单行字符串函数

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

  ascii(c1)
  c1是一字符串,返回c1第一个字母的ascii码,他的逆函数是chr()
select ascii(''a'') big_a,ascii(''z'') big_z from emp  

big_a  big_z 

65      122

  chr(<i>)[nchar_cs]
  i是一个数字,函数返回十进制表示的字符
select chr(65),chr(122),chr(223) from emp    

chr65  chr122    chr223 

a          z               b

  concat(  c1, c2 )
  c1,c2均为字符串,函数将c2连接到c1的后面,如果c1为null,将返回c2.如果c2为null,则返回c1,如果c1、c2都为null,则返回null。他和操作符||返回的结果相同
select concat(''slobo '',''svoboda'') username from dualusernames 

lobosyoboda

  initcap(c1)
  c1为一字符串。函数将每个单词的第一个字母大写其它字母小写返回。单词由空格,控制字符,标点符号限制。
select initcap(''veni,vedi,vici'') ceasar from dualceasarveni,vedi,vici

  instr(c1,[c2,<i>[,<j>]])
  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)

11

select instr(''mississippi'',''i'',-2,3) from dualinstr

(''mississippi'',''i'',3,3)

2

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

  length(c1)
  c1为字符串,返回c1的长度,如果c1为null,那么将返回null值。
select length(''ipso facto'') ergo from dualergo

10

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

  lower(c)
  返回c的小写字符,经常出现在where子串中
select lower(colorname) from itemdetail where lower(colorname) like ''%white%''

colorname

winterwhite

  lpad(c1,<i>[,c2])
  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)
  把c1中最左边的字符去掉,使其第一个字符不在c2中,如果没有c2,那么c1就不会改变。
select ltrim(''mississippi'',''mis'') from dualltrppi

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

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

  replace(c1,[c2,c3])
  c1,c2,c3都是字符串,函数用c3代替出现在c1中的c2后返回。
select replace(''uptown'',''up'',''down'') from dual

replace

downtown

  stbstr(c1,<i>[,j])
  c1为一字符串,i,j为整数,从c1的第i位开始返回长度为j的子字符串,如果j为空,则直到串的尾部。
select substr(''message'',1,4) from dual

substr

mess

  substrb(,<i>[,])
  与substr大致相同,只是i,j是以字节计算。

  soundex()
  返回与c1发音相似的词
select soundex(''dawes'') dawes, soundex(''daws'') daws, soundex(''dawson'') from dual

 

dawes daws dawsond200 d200 d250

  translate(c1,c2,c3)
  将c1中与c2相同的字符以c3代替
select translate(''fumble'',''fu'',''ra'') test from dual

text

ramble

  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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 13
    评论
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值