zoukankan      html  css  js  c++  java
  • Chapter 03Using SingleRow Functions to Customize Output(02)

    Number Functions

    ROUND:Rounds value to a specified deciaml
    TRUNC:Truncates value to a specified decimal
    MOD:Returns remainder fo division

    Function Result
    ROUND(45.926,2) 45.93
    TRUNC(45.926,2) 45.92
    MOD(1600,300) 100

    Demo-01:Using the ROUND Function

    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
    
    SQL> SELECT ROUND(45.923,2),ROUND(45.923,0),ROUND(45.923,-2) FROM dual;
    
    ROUND(45.923,2) ROUND(45.923,0) ROUND(45.923,-2)
    --------------- --------------- ----------------
              45.92              46                0
    
    SQL> SELECT ROUND(45.923,2),ROUND(45.923,0),ROUND(75.923,-2) FROM dual;
    
    ROUND(45.923,2) ROUND(45.923,0) ROUND(75.923,-2)
    --------------- --------------- ----------------
              45.92              46              100

    DUAL is a dummy table that you can use to view results from functions and calculations.

    Demo-02:Using the TRUNC Functioin

    SQL> SELECT TRUNC(45.923,2),TRUNC(45.923),TRUNC(45.923,-1) FROM DUAL;
    
    TRUNC(45.923,2) TRUNC(45.923) TRUNC(45.923,-1)
    --------------- ------------- ----------------
              45.92            45               40

    Demo-03:Using the MOD Function

    For all employees with the job title of Sales Representative,calulate the remainder of the salary after it is divided by 5000.

    View Code
    SQL> select employee_id,job_id ,MOD(salary,5000) from employees where job_id = 'SA_REP';
    
    EMPLOYEE_ID JOB_ID     MOD(SALARY,5000)
    ----------- ---------- ----------------
            150 SA_REP                    0
            151 SA_REP                 4500
            152 SA_REP                 4000
            153 SA_REP                 3000
            154 SA_REP                 2500
            155 SA_REP                 2000
            156 SA_REP                    0
            157 SA_REP                 4500
            158 SA_REP                 4000
            159 SA_REP                 3000
            160 SA_REP                 2500
    
    EMPLOYEE_ID JOB_ID     MOD(SALARY,5000)
    ----------- ---------- ----------------
            161 SA_REP                 2000
            162 SA_REP                  500
            163 SA_REP                 4500
            164 SA_REP                 2200
            165 SA_REP                 1800
            166 SA_REP                 1400
            167 SA_REP                 1200
            168 SA_REP                 1500
            169 SA_REP                    0
            170 SA_REP                 4600
            171 SA_REP                 2400
    
    EMPLOYEE_ID JOB_ID     MOD(SALARY,5000)
    ----------- ---------- ----------------
            172 SA_REP                 2300
            173 SA_REP                 1100
            174 SA_REP                 1000
            175 SA_REP                 3800
            176 SA_REP                 3600
            177 SA_REP                 3400
            178 SA_REP                 2000
            179 SA_REP                 1200
    
    30 rows selected.
  • 相关阅读:
    C# 实现保留两位小数的方法
    ueditor 上传大容量视频报http请求错误的解决方法
    Python3 message提示 AttributeError: module 'tkinter' has no attribute 'messagebox'
    Laravel5 went wrong FatalErrorException in HtmlServiceProvider.php line 36
    安装eclipse中文汉化包后无法打开eclipse
    phpstudy 下开启openssl
    mysql 数据库还原出错ERROR:Unknown command '' mysql中断
    MySql启动提示:The server quit without updating PID file(…)失败
    windows 安装 setuptools
    Nginx 域名转发
  • 原文地址:https://www.cnblogs.com/arcer/p/3016405.html
Copyright © 2011-2022 走看看