標籤:oracle函數 單行函數 字元單行函數
650) this.width=650;" src="http://s4.51cto.com/wyfs02/M01/8C/16/wKiom1hhItLi-gZ4AABh8bZO-Vc870.png-wh_500x0-wm_3-wmp_4-s_3809494292.png" title="1.png" alt="wKiom1hhItLi-gZ4AABh8bZO-Vc870.png-wh_50" />
函數的分類
=============================================================
單行函數:一個input對應一個output,input和output存在一一對應的關係 如lower
組函數: 多個input,但是只對應一個output。如 sum()
=============================================================
單行函數
特點:
每行返回一個結果,輸入輸出存在一一對應的關係
能嵌套使用 ,一個函數的輸出能做另外一個函數的輸入 如:select lowner(upper(‘aa‘)) from dual;
傳入的變數可以是列的值,也可以是運算式。 如 select lower(ename) from emp;
=============================================================
字元函數:
1、大小寫處理(upper lower),對字串
SQL>select upper(ename),sal from emp;
SQL>select lower(ename),sal from emp;
2、串連函數 concat
SQL>select concat(‘Hello‘,‘World‘) from dual;
3、截取 substr(c1,n1,n2)
n1 開始時候的位置
n2 截取的長度,預設為截取到最後。
SQL>select substr(‘HelloWorld‘,6,2) from dual;
4、instr 指定字元在某個字串中的第幾位
SQL>select instr(‘abcdefg‘,‘c‘) from dual; c在字串xxx的第幾位
SQL>select instr(‘abcdefg‘,‘c‘,-1) from dual; 從右邊往左邊數,第一個c在第幾位 第三個參數表示尋找的方向
SQL>select instr(‘abcdefgc‘,‘c‘,-1) from dual;
SQL>select instr(‘abcdefgc‘,‘c‘,-1,2) from dual;
5、取長 length
select length(‘HeloWorld‘) from dual;
select length(‘‘) from dual;
6、位元填充
①左填充 lpad(c1,n,c2) 返回指定長度為n的字串
SQL>select lpad(sal,10,‘*‘) from emp;
②右填充
SQL>select rpad(sal,10,‘*‘) from emp;
7、修剪trim
SQL>select trim(‘ Hello ‘) from dual; --截取,兩邊的空格。作用 留言板空格的問題,可能不小心按住了很多空格
SQL>select ltrim(‘ Hello ‘) from dual;
SQL>select rtrim(‘ Hello ‘) from dual;
8、例子
SQL>select empno,concat(‘name is ‘,ename) NAME,job,length(ename),instr(ename,‘A‘) "contains ‘A‘"
from emp
where substr(job,5) = ‘GER‘;
本文出自 “菜鳥達人” 部落格,請務必保留此出處http://omphy.blog.51cto.com/7921842/1886341
Oracle函數-單行函數-字元單行函數