日期:2014-05-16 浏览次数:20558 次
使用下面的日期时间函数: -TZ_OFFSET -CURRENT_DATE -CURRENT_TIMESTAMP -LOCALTIMESTAMP -DBTIMEZONE -SESSIONTIMEZONE -EXTRACT -FROM_TZ -TO_TIMESTAMP -TO_TIMESTAMP_TZ -TO_YMINTERVAL oracle9i日期时间支持 :: 在 Oracle9i 中,你能够在你的日期和时间数据中包含时区,并且提供对小数秒的支持 :: Oracle9i 中新的日期时间数据类型: -TIMESTAMP -TIMESTAMP WITH TIME ZONE (TSTZ) -TIMESTAMP WITH LOCAL TIME ZONE (TSLTZ) :: Oracle9i 服务器提供对日期时间数据类型的夏令时支持 --CURRENT_DATE :: 显示在会话时区中的当前日期和时间 ALTER SESSION SET NLS_DATE_FORMAT='DD-MON-YYYY HH24:MI:SS'; :: CURRENT_DATE 对于会话时区是敏感的 Note:the ALTER SESSION command sets the date format of the session to 'DD-MON-YYYY HH24:MI:SS' that is Day of month(1-31)-Abbreviated name of month -4-digit year Hours of dat(0-23):Minute(0-59):Second(0-59) --CURRENT_TIMESTAMP :: 显示在会话时区中的当前日期和时间,包含小数秒 ALTER SESSION SET TIME_ZONE='-5:0'; //'-8.0' SELECT SESSIONTIMEZONE,CURRENT_TIMESTAMP FROM DUAL; ::CURRENT_TIMESTAMP 对于会话时区是敏感的 ::返回值是TIMESTAMP WITH TIME ZONE 数据类型 --LOCALTIMESTAMP :: 以 TIMESTAMP 数据类型的值显示在会话时区中的当前日期和时间 ALTER SESSION SET TIME_ZONE = '-5:0'; SELECT CURRENT_TIMESTAMP, LOCALTIMESTAMP FROM DUAL; :: LOCALTIMESTAMP 返回一个 TIMESTAMP 值,而 CURRENT_TIMESTAMP 返回一个 TIMESTAMP WITH TIME ZONE 值 --DBTIMEZONE 和 SESSIONTIMEZONE :: 显示数据库时区的值 SELECT DBTIMEZONE FROM DUAL; :: 显示会话时区的值 SELECT SESSIONTIMEZONE FROM DUAL; --EXTRACT :: 从SYSDATE 中显示年 SELECT EXTRACT (YEAR FROM SYSDATE) FROM DUAL; :: 从 HIRE_DATE 中显示 MANAGER_ID 是100的雇员的月 SELECT last_name, hire_date, EXTRACT (MONTH FROM HIRE_DATE) FROM employees WHERE manager_id = 100; LAST_NAME HIRE_DATE EXTRACT(MONTHFROMHIRE_DATE) ------------------------- ---------- --------------------------- Kochhar 21-9月 -89 9 De Haan 13-1月 -93 1 Raphaely 07-12月-94 12 Weiss 18-7月 -96 7 Fripp 10-4月 -97 4 Kaufling 01-5月 -95 5 语法: SELECT EXTRACT ([YEAR] [MONTH][DAY] [HOUR] [MINUTE][SECOND] [TIMEZONE_HOUR] [TIMEZONE_MINUTE] [TIMEZONE_REGION] [TIMEZONE_ABBR] FROM [datetime_value_expression] [interval_value_expression]); TIMESTAMP WITH LOCAL TIME ZONE 存储在数据库时区中,当一个用户选择数据时,值被调整到用户会话的时区。 --***************增强 GROUP BY 子句********************* 目标 完成本课后, 您应当能够: :: 用 ROLLUP 操作产生小计值 :: 用 CUBE 操作产生交叉表值 :: 用 GROUPING 函数确定由 ROLLUP 或 CUBE 创建的行值 :: 用 GROUPING SETS 产生一个单个的结果集 Lesson Aim In this lesson you learn how to: :: Group data for obtaining the following: -Subtotal values by using the ROLLUP operator -Cross-tabulation values by using the CUBE operator :: Use the GROUPING function to identify the level of aggregation in the results set produced by a ROLLUP or CUBE operator. :: Use GROUPING SETS to produce a single result set(结果集) that is equivalent to a UNION ALL approach(方法,步骤). --**************组函数的回顾********************* 组函数在行集上操作,给出分组结果 SELECT [column,] group_function(column). . . FROM table [WHERE condition] [GROUP BY group_by_expression] [ORDER BY column]; 例子: SELECT AVG(salary), STDDEV(salary), COUNT(commission_pct),MAX(hire_date) FROM employees WHERE job_id LIKE 'SA%'; Group Functions You can use the GROUP BY clause to divide the rows in a table into groups. You can then use the group functions to return summary information for each group. Group functions can appear in select lists and in ORDER BY and HAVING clauses. The Oracle Server applies the group functions to each group of rows and returns a single result row for each group. Types of Group Functions Each of the group functions AVG, SUM, MAX, MIN, COUNT, STDDEV, and VARIANCE accept one argument. The functions AVG, SUM, STDDEV, and VARIANCE operate only on numeric values(只运算数字类型的值). MAX and MIN can operate on numeric, character, or date data values. COUNT ret