oracle 函数

一、字符函数

1、upper:将每个字母变为大写返回。

select upper('aBc') from dual

得到:ABC

2、lower:将每个字母变为小写返回。

select lower('aBc') from dual

得到:abc

3、initcap:将每个单词的第一个字母大写,其它字母变为小写返回。

select initcap('hello wOrld') from dual

得到:Hello World

4、concat:连接两个字符串。

select concat('a','B') from dual

得到:aB

select 'a'||'B'||'c' from dual

得到:aBc

concat拼接多个字符串时需要嵌套

5、substr:   substr(str,start position,length)  返回截取的字符串

select substr('hello world',0,1) from dual;    返回h
select substr('hello world',1,1) from dual;    返回h
select substr('hello world',2,1) from dual;    返回e
select substr('hello world',-3,2) from dual;   返回rl

6、length:返回字符串长度

select length(' hello world ') from dual; 返回13

7、instr:instr( string1, string2 [, start_position [, nth_appearance ] ] )

      string1:源字符串,要在此字符串中查找。

  string2:要在string1中查找的字符串.

  start_position:代表string1 的哪个位置开始查找。此参数可选,如果省略默认为1. 字符串索引从1开始。如果此参数为正,从左到右开始检索,如果此参数为负,从右到左检索,返回要查找的字符串在源字符串中的开始索引。

  nth_appearance:代表要查找第几次出现的string2. 此参数可选,如果省略,默认为 1.如果为负数系统会报错。

tips:如果String2在String1中没有找到,instr函数返回0。

select instr('hello world','o') from dual;      返回5
select instr('hello world','o',6) from dual;   返回8
select instr('hello world','o',6,2) from dual; 返回0
select instr('hello world','o',1,2) from dual; 返回8
select instr('hello world','x') from dual;       返回0

8、lpad:lpad(字段名,填充长度,填充的字符) 左侧填充

select lpad('hello world',2,'y') from dual;    返回he
select lpad('world',6,'hello ') from dual;      返回hworld
select lpad('hello',10,'y') from dual;            返回yyyyyhello

9、rpad:右侧填充

10、trim:删除首部和尾部空格的字符串

select trim(' hello world ') from dual;  返回hello world
原文地址:https://www.cnblogs.com/charles-dxb/p/3335312.html