您好,欢迎访问三七文档
当前位置:首页 > IT计算机/网络 > 数据库 > 16Oracle9i 日期函数
Copyright©OracleCorporation,2001.Allrightsreserved.Oracle9i日期函数16-2Copyright©OracleCorporation,2001.Allrightsreserved.目标通过本章学习,您将可以使用下列日期函数:•TZ_OFFSET•CURRENT_DATE•CURRENT_TIMESTAMP•LOCALTIMESTAMP•DBTIMEZONE•SESSIONTIMEZONE•EXTRACT•FROM_TZ•TO_TIMESTAMP•TO_TIMESTAMP_TZ•TO_YMINTERVAL16-3Copyright©OracleCorporation,2001.Allrightsreserved.时区-08:00上图显示了全球24个时区以及当格林威治时间是12:00时各时区的时差-05:00+02:00+10:00+07:0016-4Copyright©OracleCorporation,2001.Allrightsreserved.Oracle9i日期支持•Oracle9i中,可以将时区加入到日期和时间中而且可以将秒进行进一步的精确•日期中加入了三种新的数据类型:–TIMESTAMP(时间撮)–TIMESTAMPWITHTIMEZONE(TSTZ)(带时区的时间撮)–TIMESTAMPWITHLOCALTIMEZONE(TSLTZ)(带有本地时区的时间撮)•Oracle9i支持夏令时16-5Copyright©OracleCorporation,2001.Allrightsreserved.TZ_OFFSETSELECTTZ_OFFSET('US/Eastern')FROMDUAL;SELECTTZ_OFFSET('Canada/Yukon')FROMDUAL;SELECTTZ_OFFSET('Europe/London')FROMDUAL;•显示时区‘US/Eastern’的时差•显示时区'Canada/Yukon'的时差•显示时区'Europe/London'的时差16-6Copyright©OracleCorporation,2001.Allrightsreserved.CURRENT_DATE•CURRENT_DATE对会话所在的时区是敏感的ALTERSESSIONSETTIME_ZONE='-8:0';SELECTSESSIONTIMEZONE,CURRENT_DATEFROMDUAL;ALTERSESSIONSETTIME_ZONE='-5:0';SELECTSESSIONTIMEZONE,CURRENT_DATEFROMDUAL;•按照当前会话的时区显示当前会话的时间ALTERSESSIONSETNLS_DATE_FORMAT='DD-MON-YYYYHH24:MI:SS';16-7Copyright©OracleCorporation,2001.Allrightsreserved.CURRENT_TIMESTAMPALTERSESSIONSETTIME_ZONE='-8:0';SELECTSESSIONTIMEZONE,CURRENT_TIMESTAMPFROMDUAL;ALTERSESSIONSETTIME_ZONE='-5:0';SELECTSESSIONTIMEZONE,CURRENT_TIMESTAMPFROMDUAL;•按照当前会话的时区显示当前会话的时间•CURRENT_TIMESTAMP对会话所在的时区是敏感的•返回值是TIMESTAMPWITHTIMEZONE数据类型16-8Copyright©OracleCorporation,2001.Allrightsreserved.LOCALTIMESTAMPALTERSESSIONSETTIME_ZONE='-5:0';SELECTCURRENT_TIMESTAMP,LOCALTIMESTAMPFROMDUAL;ALTERSESSIONSETTIME_ZONE='-8:0';SELECTCURRENT_TIMESTAMP,LOCALTIMESTAMPFROMDUAL;•按照当前会话的时区显示当前会话的时间•LOCALTIMESTAMP对会话所在的时区是敏感的•返回值是TIMESTAMP数据类型16-9Copyright©OracleCorporation,2001.Allrightsreserved.DBTIMEZONE和SESSIONTIMEZONESELECTDBTIMEZONEFROMDUAL;SELECTSESSIONTIMEZONEFROMDUAL;•显示数据库所在的时区•显示会话所在的时区16-10Copyright©OracleCorporation,2001.Allrightsreserved.EXTRACTSELECTEXTRACT(YEARFROMSYSDATE)FROMDUAL;SELECTlast_name,hire_date,EXTRACT(MONTHFROMHIRE_DATE)FROMemployeesWHEREmanager_id=100;•从SYSDATE中抽出年•从HIRE_DATE中抽出月16-11Copyright©OracleCorporation,2001.Allrightsreserved.FROM_TZ应用举例SELECTFROM_TZ(TIMESTAMP'2000-03-2808:00:00','3:00')FROMDUAL;SELECTFROM_TZ(TIMESTAMP'2000-03-2808:00:00','Australia/North')FROMDUAL;16-12Copyright©OracleCorporation,2001.Allrightsreserved.SELECTTO_TIMESTAMP_TZ('1999-12-0111:00:00-8:00','YYYY-MM-DDHH:MI:SSTZH:TZM')FROMDUAL;TO_TIMESTAMP和TO_TIMESTAMP_TZ应用举例SELECTTO_TIMESTAMP('2000-12-0111:00:00','YYYY-MM-DDHH:MI:SS')FROMDUAL;16-13Copyright©OracleCorporation,2001.Allrightsreserved.TO_YMINTERVAL应用举例SELECThire_date,hire_date+TO_YMINTERVAL('01-02')ASHIRE_DATE_YMININTERVALFROMEMPLOYEESWHEREdepartment_id=20;16-14Copyright©OracleCorporation,2001.Allrightsreserved.总结•TZ_OFFSET•FROM_TZ•TO_TIMESTAMP•TO_TIMESTAMP_TZ•TO_YMINTERVAL•CURRENT_DATE•CURRENT_TIMESTAMP•LOCALTIMESTAMP•DBTIMEZONE•SESSIONTIMEZONE•EXTRACT通过本章学习,您已经可以使用:
本文标题:16Oracle9i 日期函数
链接地址:https://www.777doc.com/doc-3104568 .html