1、round 四捨五入
2、ceil 向上取整 返回 >= 該引數的最小整數select round(1.65);
select round(-1.5); #不管正數負數,先把絕對值四捨五入了,再新增正負號
select round(1.567, 2); #小數點後保留兩位進行四捨五入
3、floor 向下取整 返回小於等於該引數的最大整數select ceil(
0.0021);
# 1select ceil(
-0.2);
# 0
4、truncate 截斷 小數點後保留幾位select floor(
0.0021);
# 0select floor(
-0.002);
# -1
5、mod 取餘 結果的符號取決於被除數select
truncate
(1.699999,1
);
6、rand 獲取隨機數,返回0-1之間的小數(無限接近於1)select
mod(10,
3);select
mod(10,
-3);
select
mod(-10
,3);
1、now 返回當前系統日期和時間select rand(
)
2、curdate 返回系統當前日期select
now(
);
3、curtime 返回系統當前時間select curdate(
);
4、可以獲取指定的部分,年、月、日、小時、分鐘、秒select curtime(
);
5、str_to_date 將日期格式的字串轉換為相應日期select
year
(now()
) 年;
select
month
(now()
) 月;
select
day(
now(
)) 日;
select
year
('1998-1-1');
select monthname(
now())
;
查詢入職日期為2023年4月3號的員工資訊select str_to_date(
'99-9-13'
,'%y-%m-%d'
);
6、date_format 按指定格式將日期轉換成字串select
*from employees where hiredate = str_to_date(
'1992-4-3'
,'%y-%m-%d'
);
查詢有獎金的員工名和如入職日期(xx月/xx日 xx年)select date_format(
'2018/6/6'
,'%y年%m月%d日'
)
序號select last_name, date_format(hiredate,
'%m月%d日 %y年'
) 入職日期 from employees where commission_pct is
notnull
;
格式符功能1%y
四位的年份2%y
兩位的年份3%m
月份(01,02…11,12)4%c
月份(1, 2,…11,12)5%d
日(01, 02,…)6%h
小時(24小時制)7%h
小時(12小時制)8%i
分鐘(00, 01…59)9%s
秒(00,01,…59)
1、檢視當前版本
2、檢視當前資料庫select version(
);
3、檢視當前使用者select
database()
;
select
user()
;
單行函式(日期函式)
oracle 預設的日期格式為 dd mon yyyy select sysdate from dual d 表示2位數的日 mon month 表示月份,如 6月 mm 表示2位數的月,如 06 yyyy 表示4位數的年份 hh24 表示24小時 hh 表示12小時 mi 表示分鐘 ss 表示秒 ...
oracle 單行函式 日期函式
1.按天加 2.month between準確計算日期相差月份 select hire date,trunc sysdate hire date as 日期相減後,3.add months 月份新增 next day 得到下週某天的日期 last day 得到某月最後一天 select add mo...
oracle中單行函式日期時間函式總結
表中存在偽列 sysdate,systimestamp 偽列存在但是不顯示 select sysdate from dual select systimestamp from dual 日期計算公式 日期 天數 日期 日期 天數 日期 日期 日期 天數 函式編號 函式描述 函式使用例項 1返回 日期...