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

    oracle函数

     

    一、大小写函数

    lower():全部小写
    upper():全部大写
    initcap():首字母大写

    复制代码
    --小写
    select lower ('HAPPY') "Lowercase" from dual
    
    --大写
    select upper('last name')"Uppercase" from dual
    
    --首字母大写
    select initcap ('the socp') "Capitals" from dual
    复制代码


    二、字符控制函数

    ① Concat--连接字符串

    select concat ('happy','boy') from dual

    ② Substr

     substr('要截取的字符串',起始位置)

    select substr ('HappyBoy',2,3) from dual

    ③ length('字符串'):字符个数统计

        lengthb('字符串'):字节个数统计

    select length('快乐') 字符数,lengthb('快乐') as 字节数 from dual

    ④ instr('大字符串','小字符串') 返回小字符串在大字符串中出现的位置

    select instrb('corporate floor','or',5,2) "Instring in bytes" from dual

    ⑤ lpad()和rpad()

    lpad则与rpad相反

    select rpad('Happy',10,'*') from dual

    ⑥ trim()去除带有“a”的字符

    select trim('a' from 'ahappy') from dual


    三、日期函数

    ① months_between:两个日期相差的月数

    ② add_months:向指定日期中加上若干月数

    复制代码
    --两个日期相差的月数
    
    select months_between
    (
    to_date('02-02-1995','MM-DD-YYYY'),
    to_date('01-01-1995','MM-DD-YYYY')
    ) "Months"
    from dual
    复制代码

    --向指定日期中加上若干月数
    
    select to_char(add_months(HIREDATE,1),'DD-MON-YYYY') "Next month"
    from  emp
    where ENAME='WARD';

    -----日期相减

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

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


    四、转换函数

    隐式转换:

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

    显示转换:

    --显式转换
    select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;


    五、数字函数

    ① round():四舍五入

    select round(12.45,1) from dual;

    ② trunc:截断

    select trunc(15.79,1) "Truncate" from dual


    六、通用函数

    nvl和nvl2

    --通用函数
    select sal*12工资,comm 奖金,sal*12+nvl(comm,0) from emp
    
    select sal*12工资,comm 奖金,sal*12+nvl2(comm,comm,0) from emp


    七、decode函数

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

  • 相关阅读:
    JavaScript实现类的private、protected、public、static以及继承
    OSS网页上传和断点续传(STSToken篇)
    OSS网页上传和断点续传(OSS配置篇)
    Linq sum()时遇到NULL
    SQLSERVER事务日志已满 the transaction log for database 'xx' is full
    笔记本高分辨软件兼容问题,字体太小或模糊
    H5上传图片之canvas
    An error occurred while updating the entries. See the inner exception for details.
    无限级结构SQL查询所有的下级和所有的上级
    SQLserver 进程被死锁问题解决
  • 原文地址:https://www.cnblogs.com/hero96/p/5811112.html
Copyright © 2011-2022 走看看