Oracle 常用函数

1、连接两个字符串

1 --concat和||功能一样,只是它只能连接两个字符。
2 select concat('','景超')||',年龄27' as name from dual;
3 --------------------------结果-----------------------------
4 -- name
5 ----------------
6 --杨景超,年龄27

 

2、字母大小写转换

1 --lower('STR'):将str转为小写。
2 --upper('str'):将str转为大写。
3 --initcap('hello'):将hello首字母大写。
4 select lower('STR') as lowStr,upper('str') as uppStr,initcap('hello') as iniStr from dual;
5 -----------------------------------------结果--------------------------------------------
6 --lowstr uppstr inistr4
7 ---------------------------
8 --str STR Hello

3、检索字符串在另一字符串中的位置

1 --instr(s,c,n,n2):查找字符串c在字符串s中的位置,从第n处开始,第n2次
2 --出现的位置。
3 select instr('yang jing chao','ng',1,2) as num from dual;
4 -----------------------------------------结果---------------------------------------------
5 --lowstr uppstr inistr
6 ---------------------------
7 --str STR Hello

4、返回字符串的长度

1 --Length(str):返回str的长度
2 select length('杨景超') strLen1,length('abc') strLen2 from dual;
3 -----------------------------结果-------------------------------
4 -- strLen1 strLen2
5 --------------------
6 -- 3 3

5、截取字符串

1 --substr(str,n,n2):截取字符串str,从n开始,截取长度为n2。
2 select substr('杨景超',1,2) str,substr('Hello',1,2) str2 from dual;
3 -----------------------------结果---------------------------------
4 -- str str2
5 --------------------
6 -- 杨景 He





 



 

posted on 2012-03-02 16:22  天 火  阅读(585)  评论(0编辑  收藏  举报