codecamp

常见sql函数

一:decode 语法:DECODE(SEX,'0','男','2','女','3','其他') 无需解释一看便知。

二:trunc 语法:

  /**************日期********************/
    1.select trunc(sysdate) from dual --2017-08-18 今天的日期为2017-08-18
    2.select trunc(sysdate, 'mm') from dual --2017-08-01 返回当月第一天.
    3.select trunc(sysdate,'yy') from dual --2017-01-01 返回当年第一天
    4.select trunc(sysdate,'dd') from dual --2017-08-18 返回当前年月日
    5.select trunc(sysdate,'yyyy') from dual --2017-01-01 返回当年第一天
    6.select trunc(sysdate,'d') from dual --2017-08-13 (星期天)返回当前星期的第一天
    7.select trunc(sysdate, 'hh') from dual --2017-08-18 17:00:00 当前时间为17:35 
    8.select trunc(sysdate, 'mi') from dual --2017-08-18 17:35:00 TRUNC()函数没有秒的精确
    9.select trunc(lase_day(add_months(sysdate,-1))) --获取系统上月最后一天日期2017-07-31
    /***************数字********************/
    /*
    TRUNC(number,num_digits) 
    Number 需要截尾取整的数字。 
    Num_digits 用于指定取整精度的数字。Num_digits 的默认值为 0。
    TRUNC()函数截取时不进行四舍五入
    */
    9.select trunc(123.458) from dual --123
    10.select trunc(123.458,0) from dual --123
    11.select trunc(123.458,1) from dual --123.4
    12.select trunc(123.458,-1) from dual --120
    13.select trunc(123.458,-4) from dual --0
    14.select trunc(123.458,4) from dual --123.458
    15.select trunc(123) from dual --123
    16.select trunc(123,1) from dual --123
    17.select trunc(123,-1) from dual --120

三:to_date 语法:TO_DATE('date1'+'00:00:00','yyyy-mm-dd hh24:mi:ss')

plsql插入,并按规则生成单号
java各种文件导入导出
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

服务器相关

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }