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. 如何打造千万级Feed流系统

    from:https://www.cnblogs.com/taozi32/p/9711413.html 在互联网领域,尤其现在的移动互联网时代,Feed流产品是非常常见的,比如我们每天都会用到的朋友圈 ...

  2. Eclipse------maven使用Maven build编译web项目显示" javax.servlet.http 不存在"

    缺少javax.servlet包 解决方法: 引入下面代码即可 <project> <dependencies> <dependency> <groupId& ...

  3. IIS------如何占用80端口

    如何占用80端口 请看我的一篇随笔: https://www.cnblogs.com/tianhengblogs/p/9292347.html

  4. 架构设计:系统存储(28)——分布式文件系统Ceph(挂载)

    (接上文<架构设计:系统存储(27)--分布式文件系统Ceph(安装)>) 3. 连接到Ceph系统 3-1. 连接客户端 完毕Ceph文件系统的创建过程后.就能够让客户端连接过去. Ce ...

  5. js中toFixed() 的使用(转)

    转载:http://www.studyofnet.com/news/292.html 一.定义和用法 toFixed() 方法可把 Number 四舍五入为指定小数位数的数字. 语法 NumberOb ...

  6. audio_policy.conf说明(翻译)

    自己记着当笔记,水平有限,仅供参考 # # Audio policy configuration for generic device builds (goldfish audio HAL - emu ...

  7. 【.netcore基础】MVC制器Controller依赖注入

    废话少说,直接上代码 首先我们得有一个接口类和一个实现类,方便后面注入MVC里 接口类 public interface IWeatherProvider { List<WeatherForec ...

  8. WP8.1开发:简单天气预报应用(转)

    今天小梦给大家分享一个简单的天气预报应用源码:调用的是百度API.整个应用都没有什么难点.只是一个简单的网络请求和json数据处理.在WP8.1有小娜的情况下,天气预报应用还有意义吗?我认为还是有点意 ...

  9. WP8.1学习系列(第七章)——应用选项卡Pivot交互UX

    “应用选项卡”模式用于用户经常在中间导航的多个 UI 页面.如果你的应用基于单个主题(例如,电影.棒球等),该模式尤其有用.每页都将为用户显示与该应用呈现的整体数据相关的一些内容.“应用选项卡”模式可 ...

  10. Web编辑器的使用

    1.复制web编辑器到你的项目中的表现层(UI) 2.添加引用:FredCK.FCKeditorV2.dll到你的项目中来 3.页面中加引用 <%@ Register TagPrefix=&qu ...