1. 程式人生 > >oracle 常用字符串函數

oracle 常用字符串函數

substr lower uoj per 不足 rpad mod 查詢 修改

select initcap(‘guodongdong‘) from dual; /返回字符串並將字符串的第一個字母變為大寫;
select initcap(ename) from scott.emp; /針對scott.emp表中的ename開頭全部大寫。
select lower(ename) from scott.emp; /針對scott.emp表中的ename名字中全部小寫。
select * from scott.emp where lower(ename)=‘scott‘; /以防scott中有大小寫。
select upper(ename) from scott.emp; /針對scott.emp表中的ename名字全部大寫
select length(ename) from scott.emp; /查詢scott.emp表中的ename名字所占的單詞個數。
select ename,substr(ename,length(ename)-2) from scott.emp /查詢Scott.emp表中的ename名字最後的三個英文名稱。
或者 select ename,substr(ename,-3) from scott.emp;
select concat(‘guo‘,‘dongdong‘) from dual; /CONCAT只能連接兩個字符串,沒有|| 強大。
select concat(ename,sal) from scott.emp; /針對scott.emp表中的名字個工資做一個連接。
select substr(‘guodongdong‘,1,5) from dual; /查詢guodongdong,從左邊1-5的單詞列出。
select subsrt(‘guodongdong‘,-1,5) from dual; /從右邊開始。
select subsrt(‘guodongdong‘,-1) from dual; /截取末尾;
select lpad(‘guodongdong‘,15,‘*‘) from dual; /顯示guodongdong,15表示15為,不夠15為則在前方補*。
select rpad(‘guodongdong‘,15,‘*‘) from dual; /顯示guodongdong,15表示15為,不夠15為則在後方補*。
select lpad(ename,length(ename)+30,‘*‘ )from scott.emp;
select lpad (ename,length(ename)+30,‘*‘) from scott.emp;
select rpad (lpad (ename,length(ename)+30,‘*‘),length(lpad(ename,length(ename) +30,‘*‘)) +30,‘*‘) from scott.emp;
select replace(‘guodongdong‘,‘d‘,‘j‘) from dual; /修改guodongdong,d單詞全部替換為j,則是guojongjong
select trim(‘k‘ from ‘gkgguodonkkgdonggg‘) from dual; /只要gkgguodonkkgdonggg去除指定字符的前後空格。
ltrim
rtrim
三個主要函數:ROUND,trunc,mod
1: SELECT
round(78915.67823823), 78916,小數點之後的內容直接進行四舍五入
round(78915.67823823,2), 78915.68,保留兩位小數
round(78915.67823823,-2), 78900,把不足5的數據取消了
round(78985.67823823,-2), 79000,如果超過了5則進行進位
round(-15.65) ; -16
from dual;
2:截取小數,所有的小數都不進位
SELECT
trunc(78915.67823823), 78916,小數點之後的內容直接進行四舍五入
trunc(78915.67823823,2), 78915.68,保留兩位小數
trunc(78915.67823823,-2), 78900,把不足5的數據取消了
trunc(78985.67823823,-2), 79000,如果超過了5則進行進位
trunc(-15.65) ; -16
from dual;
3:求模(求余數)
select mod(10,3) from dual; 得1

oracle 常用字符串函數