SQL Fundamentals || Oracle SQL语言

数字函数number functions

  • Number functions - Accepts numeric input and returns numeric values. Functions under the category are ROUND, TRUNC, and MOD.
    • ROUND and TRUNC functions are used to round and truncate the number value.
    • MOD is used to return the remainder of the division operation between two numbers.

function

result

ROUND

Rounds value to a specified decimal

四舍五入

TRUNC

Truncates value to a specified decimal

截断一个值到一定的小数位,不管大于5小于5

MOD

Returns remainder of division

返回一个除数的余数

function

result

ROUND(45.926,2)

45.93

TRUNC(45.926,2)

45.92

MOD(1600,300)

100

function

purpose

ROUND(column | expression,n)

Rounds (四舍五入)the column, expression, or value to n decimal places(小数位) or, if n is omitted(省略), no decimal places (if n degative, numbers to the left of decimal point are rounded.)

如果n是负数,小数点左边四舍五入

SQL> SELECT ROUND(45.923,2),ROUND(45.923,0),ROUND(45.923,-1) FROM DUAL;

ROUND(45.923,2) ROUND(45.923,0) ROUND(45.923,-1)

--------------- --------------- ----------------

45.92              46               50

TRUNC(column | expression,n)

Truncates(截断) the column, expression, or value to n decimal places or, if n is omitted, n defaults to zero.

Like the ROUND function, the TRUC function can be used with date functions.

TRUNC函数也可以用作日期函数.

MOD(m,n)

Returns the remainder(余数) of m divided by n

Note : The MOD function is often used to determine whether a value is odd or even.

The MOD function is also the ORACLE hash function.

MOD函数经常被用于判断一个值是奇数还是偶数.

对数字进行处理,例如:四舍五入;

函数名称

描述

ROUND(数字 [,保留位数])

对小数进行四舍五入,可以指定保留位数,如果不指定,则表示将小数点之后的数字全部进行四舍五入

SELECT ROUND(789.652),ROUND(789.652,2),ROUND(789.652,-1) FROM DUAL;

ROUND(789.652) ROUND(789.652,2) ROUND(784.652,-1)

-------------- ---------------- -----------------

790           789.65               780

以上分别是不保留小数,保留两位小数,处理整数进位.

SELECT ename,job,sal,ROUND(sal/30,2) FROM emp;

TRUNC(数字 [,截取位数])

保留指定位数的小数,如果不指定,则表示不保留小数

SQL> SELECT TRUNC(789.652),TRUNC(789.652,2),TRUNC(789.652,-2) FROM DUAL;

TRUNC(789.652) TRUNC(789.652,2) TRUNC(789.652,-2)

-------------- ---------------- -----------------

789           789.65               700

MOD(数字,数字)

取模,求余数

SQL> SELECT MOD(10,3) FROM DUAL;

MOD(10,3)

----------

1

SQL Fundamentals || Single-Row Functions || 数字函数number functions的更多相关文章

  1. SQL Fundamentals || Single-Row Functions || 字符函数 character functions

    SQL Fundamentals || Oracle SQL语言   SQL Fundamentals: Using Single-Row Functions to Customize Output使 ...

  2. SQL Fundamentals || Single-Row Functions || 日期函数date functions

    SQL Fundamentals || Oracle SQL语言   SQL Fundamentals: Using Single-Row Functions to Customize Output使 ...

  3. Oracle Single-Row Functions(单行函数)——NULL-Related Functions

    参考资料:http://docs.oracle.com/database/122/SQLRF/Functions.htm#SQLRF006 Single-row functions return a ...

  4. SQL Fundamentals || Single-Row Functions || 转换函数 Conversion function

    SQL Fundamentals || Oracle SQL语言   SQL Fundamentals: Using Single-Row Functions to Customize Output使 ...

  5. SQL Fundamentals: Using Single-Row Functions to Customize Output使用单行函数自定义输出

    SQL Fundamentals || Oracle SQL语言 DUAL is a public table that you can use to view results from functi ...

  6. SQL Fundamentals || Single-Row Functions || 通用函数 General function || (NVL,NVL2,NULLIF,DECODE,CASE,COALESCE)

    SQL Fundamentals || Oracle SQL语言 SQL Fundamentals: Using Single-Row Functions to Customize Output使用单 ...

  7. SQL Fundamentals || Oracle SQL语言

    对于SQL语言,有两个组成部分: DML(data manipulation language) 它们是SELECT.UPDATE.INSERT.DELETE,就象它的名字一样,这4条命令是用来对数据 ...

  8. 微软BI 之SSIS 系列 - Execute SQL Task 中的 Single Row 与 Full Result Set 的处理技巧

    开篇介绍 Execute SQL Task 这个控件在微软BI ETL 项目中使用的频率还是非常高的,也是大部分入门 SSIS 初学者最早接触到的几个控制流控件. 我们通常使用 Execute SQL ...

  9. 高精度运算专题-输出函数与字符串转数字函数(Output function and the string to number function)

    输出函数:这个函数别看它小,但浓缩的都是精华啊 作用:对于高精度的数组进行倒序输出 思路:首先从被传入的数组第一位开始,一直往前扫输出就可以了(i--) 注释:因为每个数组的第一位是用来存储这个数组的 ...

随机推荐

  1. jQuery获取CSS样式中的颜色值的问题

    转自:http://blog.csdn.net/cwj649956781/article/details/23261529 jQuery获取CSS样式中的颜色值的问题,不同浏览器格式不同的解决办法,需 ...

  2. 海康视频监控---Demo

    1,使用在页面中调用ActiveX控件 <object classid='clsid:E7EF736D-B4E6-4A5A-BA94-732D71107808' codebase='' stan ...

  3. javascript 作用域、作用域链理解

    JavaScript作用域就是变量和函数的可访问范围. 1.变量作用域 在JavaScript中,变量作用域分为全局作用域和局部作用域. 全局作用域 任何地方都可以定义拥有全局作用域的变量 1.没有用 ...

  4. linux 查看硬件信息

      1.查看内存槽数.那个槽位插了内存,大小是多少 dmidecode|grep -P -A5 "Memory\s+Device"|grep Size|grep -v Range ...

  5. OBS显示器获取显示黑色没有图像

  6. OSG添加回调更新

    class CB : public osg::NodeCallback { virtual void operator()(osg::Node* node, osg::NodeVisitor* nv) ...

  7. Android中的安全与访问权限控制

    Android是一个多进程系统,在这个系统中,应用程序(或者系统的部分)会在自己的进程中运行.系统和应用之间的安全性是通过Linux的facilities(工具,功能)在进程级别来强制实现的,比如会给 ...

  8. com.baidu.mapapi.CoordType

    2.2.2升级到3.0.1百度报错了, 一:请检查.jar,.so是否是最新的 二:clear

  9. Struts2(一)基本配置

    一.Struts2概述 1.什么是Struts2? Struts2以WebWork为核心,采用拦截器的机制来处理用户的请求,这样使得业务逻辑控制器能够和ServletAPI脱离开来. 2.工作原理 当 ...

  10. 【LeetCode OJ】Remove Element

    题目:Given an array and a value, remove all instances of that value in place and return the new length ...