zoukankan      html  css  js  c++  java
  • 单行函数

    1.  select  upper('hello world' 大写,lower('hello world') 小写,initcap('hello world') 首字母大写  from dual;

    2.   select length('中国') 字符,lengthb('中国')  字节 from dual;

                                 2                           6

    3.  select replace ('hello','o'.'a') from dual;  --用a 替换 o

    4. select substr('hello world',3,4) from dual;   --从第三位开始截取4个字符串

    5. select instr('hello world','o') from dual;  --查找  o 的位置

                                      5

    6.select lpad('hello world',15,'*') 左补齐,rpad('hello world',15,'@')  右补齐 from dual;

       --左右 补齐  用不同符号 补齐15位

    7. select trim('h' from 'hello world') from dual;   --(只能)截取一个字符

    8. round(42.965,2)  四舍五入  保留两位小数

        trunc(42.965,2)  舍去  保留小数点后两位

        mod(10,3)   取余数 10/3 = 1

    9. 暂时更改系统时间方式

        select sysdate from dual;

        select * from v&nls_parameters;  --查看系统格式

        alter session set NLS_DATE_FORMAT='yyyy-mm--dd';   暂时 更改系统时间格式为:

       改变时间的显示的另一种方式

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

    10. select (sysdate + 1) - (sysdate) from dual;   --明天 减去今天 等于

          日期不能去做加法,只能加几天,可以做减法,减去一个日期或者几天

    11.  select (sysdate - hiredate)/30   粗略,months_between(sysdate,hiredate)   精确 from dual;   --计算月份差

    12.  在一个日期上加上几个月

          select add_months(sysdate,5)  from dual;

    13查看当前月的最后一天   last_day(sysdate)

        下一个日期 比如下一个星期六    next_day(sysdate,'星期二')

    14. select to_char(sysdate,'"今天是"yyyy-mm-dd day "天气真的很好"') from dual;

         今天是2016-03-15 星期二 天气真的很好 

    15将整数转换为一个字符串

       select to_char(1524251,'L999,999') from dual;   --L 表示本地货比

    16.  select to_number('123') from dual;  转换为数字类型

    17. nvl2(a,b,c) 如果a==null ,返回c否则返回b

           nullif(a,b) 如果a == b 返回空,如果不等于返回a

         coalesce(a,b,c....)  从最左边开始查找,查找到第一个不为空的返回

  • 相关阅读:
    BZOJ1527 : [POI2005]Pun-point
    2016-2017 ACM-ICPC Southwestern European Regional Programming Contest (SWERC 2016)
    2016-2017 ACM-ICPC Northwestern European Regional Programming Contest (NWERC 2016)
    NAIPC-2016
    BZOJ2498 : Xavier is Learning to Count
    ACM ICPC Vietnam National Second Round
    XVI Open Cup named after E.V. Pankratiev. GP of Ukraine
    XVI Open Cup named after E.V. Pankratiev. GP of Peterhof
    HDU5509 : Pattern String
    BZOJ4583 : 购物
  • 原文地址:https://www.cnblogs.com/savepoint/p/5330446.html
Copyright © 2011-2022 走看看