Oracle 數字操作。數字函數。mod(),trunc(),round(),ceil(),floor的使用

來源:互聯網
上載者:User

標籤:大整數   忽略   小數   四捨五入   部分   日期   情況   div   指定   

1,取整函數(ceil 向上取整,floor 向下取整)

第一種方式:

select  trunc( 65/33) from dual  -- 取整 trunc (1.9) = 1

第二種方式

 select ceil(66.6) N1,floor(66.6) N2 from dual;

2, 取冪(power) 和 求平方根(sqrt)

 select power(3,2) N1,sqrt(9) N2 from dual;

3,求餘

 select mod(9,5) from dual;

4,返回固定小數位元 (round:四捨五入,trunc:直接截斷)

 select round(66.667,2) N1,trunc(66.667,2) N2 from dual; 

5,傳回值的符號(正數返回為1,負數為-1)

 select sign(-32),sign(293) from dual;

1.round函數(四捨五入)

描述 : 傳回一個數值,該數值是按照指定的小數位元數進行四捨五入運算的結果參數:number : 欲處理之數值decimal_places : 四捨五入 , 小數取幾位 ( 預設為 0 )
select round(123.456, 0)   from dual; 返回123select round(123.456, 1)   from dual;  返回123.5select round(-123.456, 2) from dual;   返回-123.46

2.ceil和floor函數

ceil和floor函數在一些業務資料的時候,有時還是很有用的。ceil(n) 取大於等於數值n的最小整數;floor(n)取小於等於數值n的最大整數
select ceil(1.5) a from dual;  返回2select ceil(-1.5) a from dual; 返回-1select floor(1.5) a from dual;  返回1select floor(-1.5) a from dual; 返回-2

1)trunc函數處理數字

TRUNC(number[,decimals])

其中:number 待做截取處理的數值decimals 指明需保留小數點後面的位元。可選項,忽略它則截去所有的小數部分。trunc就是處理數位顯示位元,如果decimals為負數,就處理整數部分,處理完為0,-1就是各位為零,-2就到了十位,如果超過了 整數部分長度,則整個數字0; 2)處理日期    trunc函數返回以指定元元素格式截去一部分的日期值。其具體的文法格式如下:TRUNC(date,[fmt])其中:date為必要參數,是輸入的一個日期值fmt參數可忽略,是日期格式,用以指定的元素格式來截去輸入的日期值。忽略它則由最近的日期截去下面是該函數的使用方式:
trunc(sysdate,‘yyyy‘) --返回當年第一天.trunc(sysdate,‘mm‘) --返回當月第一天.trunc(sysdate,‘d‘) --返回當前星期的第一天.selecttrunc(sysdate,‘YYYY‘)from dual;selecttrunc(sysdate,‘MM‘)from dual;selecttrunc(sysdate,‘D‘)from dual;

 

Oracle 數字操作。數字函數。mod(),trunc(),round(),ceil(),floor的使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.