round日期函式 天數如何四捨五入

2021-06-26 22:36:01 字數 984 閱讀 5641

--講解:年份按**1-6月和7-12月**四捨五入到最近的 幾幾年1月1日

select round(to_date('6-2月-13'),'year') from dual;

select round(to_date('6-5月-13'),'year') from dual;

select round(to_date('6-7月-13'),'year') from dual;

--講解:月份按**1-15日和16-30日**四捨五入到最近的 幾月1日

select round(to_date('15-2月-13'),'month') from dual;

select round(to_date('16-2月-13'),'month') from dual;

--講解:天數按**周一-週三和周四到週日**四捨五入到最近的 週日

--去掉注釋不然會有錯誤測試:

select round(to_date('3-2月-13'),'day') from dual;--週日

select round(to_date('4-2月-13'),'day') from dual;--周一

select round(to_date('5-2月-13'),'day') from dual;--周二

select round(to_date('6-2月-13'),'day') from dual;--週三

以上都是2月3日

以下都是2月10日

select round(to_date('7-2月-13'),'day') from dual;--周四

select round(to_date('8-2月-13'),'day') from dual;--周五

select round(to_date('9-2月-13'),'day') from dual;--週六

select round(to_date('10-2月-13'),'day') from dual;--週日

SQL的四捨五入ROUND函式

sql四捨五入2007 11 01 16 35問題1 select cast 123.456 as decimal 將會得到 123 小數點後面的將會被省略掉 如果希望得到小數點後面的兩位。則需要把上面的改為 select cast 123.456 as decimal 38,2 123.46 自動...

MS SQL的ROUND函式用來數值的四捨五入

ms sql的round函式用來數值的四捨五入 ms sql要進行數值的四捨五入,有一好用的函式round。語法 round numeric expression length function 引數numeric expression 精確數值或近似數值資料類別 bit 資料型別除外 的表示式。l...

模擬round內建函式,實現四捨五入函式

首先了解下round函式,很簡單,對浮點數進行近似取值,保留幾位小數 用法 round number,ndigits number 要四捨五入的數,ndigits 要小數點後保留的位數在實際使用中發現round函式並不總是如上所說的四捨五入。如 in 14 round 2.355,2 out 14 ...