zoukankan      html  css  js  c++  java
  • Oracle函数

    Oracle SQL函数

     

    Oracle将函数大致分为单行函数,聚合函数和分析函数。

    单行函数分为字符函数,日期函数,转换函数,数字函数,通用函数,decode函数

    一.字符函数

     1)大小写控制函数

        01.Lower() 全部小写

    --字符函数
    --小写
    select Lower ( 'HAPPY') from dual;

    效果:

       02.Upper()  全部大写

    --大写
    select Upper ('happy') from dual;

    效果:

       03.initcap()  首字母大写 

    --首字母大写
    select initcap ('happy') from dual;

     效果:

    2)字符控制函数

         01.concat()   拼接

    --拼接
    select concat('happy','boy') from dual;

    效果:

         02.substr()   截取字符

    --截取字符串 位置从1开始
    select substr('happyboy',6) from dual;

    效果:

    --要截取的字符,起始位置,取几个字符
    select substr('happyboy',6,3) from dual;

    效果:

        03.length()和lengthb()

      --length('字符串'):字符个数统计
       -- lengthb('字符串'):字节个数统计
    select length('呵呵') 字符数,lengthb('呵呵') as 字节数 from dual;

    效果:

        04.instr()

    --instr('大字符串','小字符串')返回小字符串在大字符串中出现的位置
    select instr('happy hehe','he',2,2) "Instring" from dual;

    select instr('happy hehe','he',-2,2) "Reversed Instring" from dual;

    效果:

    select instr('happy hehe','he',2,2) "Instring in bytes" from dual;

    效果:

        05.lpad()和rpad()

    --lpad()和rpad()
    select lpad('happy',10,'*') from dual;

    效果:

    二.日期函数

    1)日期函数

         01.两个日期相差的月数

    select MONTHS_BETWEEN
    (TO_DATE('02-02-1995','MM-DD-YYYY'),
    TO_DATE('01-01-1995','MM-DD-YYYY')) "Months"
    from dual;

    效果:

        02.向指定日期中加上若干月数

    --向指定日期中加上若干月数
    select TO_CHAR(ADD_MONTHS(hiredate,1),'DD-MON-YYYY') "Next month" 
    from emp
    where ENAME='JONES';

    效果:

    2)日期相减

        01.两个日期间的天数

    --两个日期间的天数
    select floor(sysdate-to_date('20020405','yyyymmdd')) from dual;

    效果:

        02.两个日期相差的月数

    --两个日期相差的月数
    select months_between(sysdate,to_date('20111204','yyyymmdd')) from dual;

    效果:

    三。转换函数

    1)隐式转换

    --转换函数
    --隐式函数
    select * from emp
    where hiredate='17-12月-80';

    效果:

    2)显示转换

       01.to_char()对日期的转换

    --显式函数
       --01.to_char()对日期的转换
       select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;

    效果:

       02.to_char()对数字的转换

    --02.to_char()对数字的转换
       select to_char(sal,'L9,999.99') 
       from emp;

    效果:

    四.数字函数

        01.Round()

    --数字函数
      --01.Round()四舍五入
      select round(12.45,1) from dual;

    效果:

        02.trunc()截断

     --02.trunc()截断
      select trunc(15.19,1) "Truncate" from dual;

    效果:

     五.通用函数

    nvl和nvl2滤空函数

       01.nvl滤空函数

    select sal*12工资,comm 奖金,sal*12+nvl(comm,0) from emp;

    效果:

       02.nvl2滤空函数

    select sal*12工资,comm 奖金,sal*12+nvl2(comm,comm,0) from emp;

    效果:

     六.decode函数

    复制代码
    --decode函数
      select ename,empno,
          decode (ename,'SMITH',1,
          'ALLEN',2,
          'WARD',3,
          'JONES',4) "Location"
          from emp
          where empno<7600
          order by empno,"Location"
    复制代码

    效果:

     
     
     
  • 相关阅读:
    安装APK失败,错误代码:INSTALL_FAILED_INVALID_APK 解决方案
    android保持服务不休眠(持续运行)以及唤醒屏幕的方法
    判断Android 当前版本是否为debug版本
    Android 使用WebView加载含有Canvas的页面截屏处理
    喜大普奔,微软Microsoft JDBC Driver For SQL Server已发布到maven中央仓库
    系统架构设计理论与原则、负载均衡及高可用系统设计速记
    Sharing A Powerful Tool For Application Auto Monitor
    Sharing A Powerful Tool For Calculate Code Lines
    关于GC和析构函数的一个趣题
    垃圾回收机制GC知识再总结兼谈如何用好GC
  • 原文地址:https://www.cnblogs.com/1And0/p/5811197.html
Copyright © 2011-2022 走看看