Oracle數據庫函數總結


1、ceil()向上取整,結果為124。
select ceil(123.123) from dual;
2、floor()向下取整,結果為123。
select floor(123.123) from dual;
3、trunc(n1,n2)取整函數,n1代表字符串,n2代表小數位數,結果為123.12。
select trunc(123.125,2) from dual;
4、round(n1,n2)四舍五入,n1代表字符串,n2代表小數位數,結果為123.57。
select round(123.567) from dual;
5、lower()將字符串轉化為小寫,結果為abc。
select lower(‘ABC’) from dual;
6、upper()將字符串轉化為大寫,結果為ABC。
select upper(‘abc’) from dual;
7、字符串拼接,結果為 ‘Hello,小明’。詳細:http://luzhiming.top/?id=35
select concat(‘Hello’,’,小明’) from dual;

to_char()轉化為字符串

8、時間是12小時制,結果2018-07-06 05:07:20
select to_char(sysdate,’yyyy-mm-dd hh:mm:ss’) from dual;
9、時間是24小時制,結果2018-07-06 17:07:33
select to_char(sysdate,’yyyy-mm-dd hh24:mm:ss’) from dual;
10、時間是帶上下午的12小時制,結果2018-07-06 下午05:07:03
select to_char(sysdate,’yyyy-mm-dd pmhh:mm:ss’) from dual;
11、時間是帶上下文的24小時制,結果2018-07-06 下午17:07:49
select to_char(sysdate,’yyyy-mm-dd pmhh24:mm:ss’) from dual;

to_date()轉化為日期

12、格式化日期,結果為25-4月 -17
select to_date(‘2017-04-25’,’yyyy-mm-dd’)from dual;—格式化日期

計算函數

13、count()函數,統計一共有多少條數據,假如表中有20條數據,count()結果則為20。
select count(*) from table_name;
14、min(),查詢列的最小值。
15、max(),查詢列的最大值。
16、avg(),查詢列平均數。
17、sum(),查詢列的總和,只能是數值型。
18、mod(n1,n2),n1/n2 求余數。結果2。
select mod(2, 3)from dual;

字符串截取

19、substr(n1,n2,n3) n1是截取的字符串,n2開始截取位置,n3是截取多少位 結果是321
select substr(‘13122123456’, 2,3) from dual;
20、substring(n1, n2, n3) n1是截取的字符串,n2開始下標,n3結束下標 結果是122
select substr(‘13122123456’, 2,5) from dual;
21、decode()函數判斷,sex為0則顯示女,1則顯示男,其他顯示未知
select decode(sex,0,’女’,1,’男’,’未知’) from student;

空置置換

22、nvl(n1,n2)函數,n1為空則顯示n2,不為空則顯示n1值。n2值可自己根據需要設置
select nvl(n1, n2) from table_name;
23、nvl2(n1,n2,n3)函數,n1為空則顯示n3,不為空則顯示n2。
select nvl2(n1,n2,n3) from table_name;

拼音轉換

24、fn_getpy()函數,漢字進行拼音轉換。
select fn_getpy(‘魯智深’,0) from dual; 結果:luzhishen
select fn_getpy(‘魯智深’) from dual; 結果:luzhishen
select fn_getpy(‘魯智深’,1) from dual; 結果:LUZHISHEN
select fn_getpy(‘魯智深’,2) from dual; 結果:LuZhiShen
select fn_getpy(‘魯智深’,3) from dual; 結果:lzs
select fn_getpy(‘魯智深’,4) from dual; 結果:LZS


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM