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. Java并发编程、内存模型与Volatile

    http://www.importnew.com/24082.html  volatile关键字 http://www.importnew.com/16142.html  ConcurrentHash ...

  2. SpringBoot------热部署(Springloaded)

    为啥要热部署: 在修改代码的时候,不需要重新启动程序,程序会自动进行编译 注意: 控制器中新增加的方法是不能进行热部署的 方法: 1.在pom.xml文件里面添加下面代码 <project> ...

  3. Mybatis -- 批量更新 -- updateBatch

    mysql数据库配置: 数据库连接必须配置:&allowMultiQueries=true并且‘&’ 用&替换 jdbc.url=jdbc:mysql://192.168.10 ...

  4. backbone学习笔记:集合(Collection)

    集合(Collection)是一个Backbone对象,用来组织和管理多个模型,它不仅仅是一个javascript数组,还提供了专门的方法来对集合进行排序.过滤和遍历,集合可以方便的与REST服务器进 ...

  5. CMD打开模拟器

    CMD-> CD d:\android\android-sdk-151\tools-> (这里的路径是你emulator.exe所在的路径) emulator -avd avdname-& ...

  6. Oracle的闪回技术--闪回已删除的表

    注意闪回技术只能保护非系统表决空间中的表,而且表空间必须本地管理, 外键将不可以被恢复, 索引和约束的名字将会被命名为以BIN开头,由系统生成的名字 查看是否开启闪回: SQL> show pa ...

  7. Expected BEGIN_ARRAY but was BEGIN_OBJECT

    Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 3519 path $.data[1].inspector_user Gson 中 ...

  8. HIGHGUI ERROR: V4L/V4L2: VIDIOC_S_CROP错误解决方法

    在树莓派上运行在windows上正确的程序,  报错: HIGHGUI ERROR: V4L/V4L2: VIDIOC_S_CROP OpenCV Error: Assertion failed (s ...

  9. 【PHP】 curl 上传文件 流

    在运行过程中, 以下两种方式要看你的PHP 版本 'file' =>'@' .$filePath 'file' =>new CURLFile(realpath($filePath)) 本次 ...

  10. Delphi中ClientDataSet的用法小结

    Delphi中ClientDataSet的用法小结 TClientDataSet控件继承自TDataSet,其数据存储文件格式扩展名为 .cds,是基于文件型数据存储和操作的控件.该控件封装了对数据进 ...