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"
    复制代码

  • 相关阅读:
    【PHP】php基础回顾
    【PHP】MVC架构
    【OpenGL学习】使用VBO和FBO
    【OpenGL学习】使用Shader做图像处理
    hdu 杭电 1242 Rescue 果枫
    并查集模板 果枫
    数组结构体中排序 果枫
    hdu 杭电 1728 逃离迷宫 果枫
    hdu 杭电 1241 Oil Deposits 果枫
    hdu 杭电 2216 Game III 果枫
  • 原文地址:https://www.cnblogs.com/hero96/p/5811112.html
Copyright © 2011-2022 走看看