16 Copyright © Oracle Corporation, 2001. All rights reserved. Oracle9 i Datetime Functions.

Slides:



Advertisements
Similar presentations
Using the Set Operators
Advertisements

Copyright  Oracle Corporation, All rights reserved. 2 Single-Row Functions.
Copyright  Oracle Corporation, All rights reserved. 10 Creating and Managing Tables.
4 Copyright © 2004, Oracle. All rights reserved. Reporting Aggregated Data Using the Group Functions.
5 Copyright © 2007, Oracle. All rights reserved. Reporting Aggregated Data Using the Group Functions.
9 Copyright © Oracle Corporation, All rights reserved. Creating and Managing Tables.
18 Copyright © Oracle Corporation, All rights reserved. Advanced Subqueries.
10 Copyright © Oracle Corporation, All rights reserved. Including Constraints.
8 Copyright © Oracle Corporation, All rights reserved. Manipulating Data.
1 Copyright © Oracle Corporation, All rights reserved. Writing Basic SQL SELECT Statements.
Advanced Topics: Business Intelligence Features
2 Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data.
9 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Using the Set Operators Assist. Prof. Pongpisit Wuttidittachotti, Ph.D. Faculty.
Using Single-Row Functions to Customize Output
Oracle9 i Datetime Functions Fresher Learning Program January, 2012.
17 Copyright © Oracle Corporation, All rights reserved. Enhancements to the GROUP BY Clause.
1 Copyright © Oracle Corporation, All rights reserved. Writing Basic SQL SELECT Statements.
13 Copyright © Oracle Corporation, All rights reserved. RMAN Complete Recovery.
Single-Row Functions. SQL Functions Functions are a very powerful feature of SQL and can be used to do the following: Perform calculations on data Modify.
1 Copyright © 2006, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement.
Said Salomon Unitrin Direct Insurance T-SQL Date and Time Functions Said Salomon.
3 Copyright © Oracle Corporation, All rights reserved. Single-Row Functions.
2 Copyright © Oracle Corporation, All rights reserved. Restricting and Sorting Data.
2 Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data.
4 Copyright © 2006, Oracle. All rights reserved. Restricting and Sorting Data.
Copyright Ó Oracle Corporation, All rights reserved. 22 Running a Form Builder Application.
10 Copyright © 2009, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables.
1 Copyright © 2006, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables.
Copyright © 2004, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables.
4 Copyright © 2004, Oracle. All rights reserved. Reporting Aggregated Data Using the Group Functions.
3 Copyright © 2004, Oracle. All rights reserved. Using Single-Row Functions to Customize Output.
10 Copyright © Oracle Corporation, All rights reserved. Including Constraints.
20 Copyright © Oracle Corporation, All rights reserved. Oracle9 i Extensions to DML and DDL Statements.
9 Copyright © Oracle Corporation, All rights reserved. Creating and Managing Tables.
Copyright  Oracle Corporation, All rights reserved. 10 Creating and Managing Tables.
15 Copyright © Oracle Corporation, All rights reserved. RMAN Incomplete Recovery.
10 Copyright © Oracle Corporation, All rights reserved. Including Constraints.
2 第二讲 Restricting and Sorting Data. Objectives After completing this lesson, you should be able to do the following: Limit the rows retrieved by a query.
Copyright © 2004, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement Satrio Agung Wicaksono, S.Kom., M.Kom.
Copyright © 2004, Oracle. All rights reserved. Lecture 4: 1-Retrieving Data Using the SQL SELECT Statement 2-Restricting and Sorting Data Lecture 4: 1-Retrieving.
2 Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data.
15 Copyright © Oracle Corporation, All rights reserved. Using SET Operators.
9 Copyright © Oracle Corporation, All rights reserved. Creating and Managing Tables.
Copyright © 2004, Oracle. All rights reserved. Using the Set Operators.
3 Copyright © 2009, Oracle. All rights reserved. Using Single-Row Functions to Customize Output.
3 Copyright © Oracle Corporation, All rights reserved. Single-Row Functions.
6 Copyright © Oracle Corporation, All rights reserved. Subqueries.
2 Copyright © 2004, Oracle. All rights reserved. Using Globalization Support.
Using SET Operators Fresher Learning Program January, 2012.
6 Copyright © 2007, Oracle. All rights reserved. Retrieving Data Using Subqueries.
1 Copyright © Oracle Corporation, All rights reserved. Writing Basic SQL SELECT Statements.
2 Copyright © 2009, Oracle. All rights reserved. Restricting and Sorting Data.
5 Copyright © 2004, Oracle. All rights reserved. Managing Data in Different Time Zones.
Declaring PL/SQL Variables
19 Copyright © Oracle Corporation, All rights reserved. Hierarchical Retrieval.
5 Copyright © 2009, Oracle. All rights reserved. Managing Data in Different Time Zones.
3 Copyright © 2004, Oracle. All rights reserved. Using Single-Row Functions to Customize Output.
3 Copyright © 2009, Oracle. All rights reserved. Using Single-Row Functions to Customize Output.
1 Copyright © 2007, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement.
1 Copyright © 2009, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement.
13 Copyright © 2004, Oracle. All rights reserved. Migrating SQL Statements.
4 Copyright © 2009, Oracle. All rights reserved. Using Conversion Functions and Conditional Expressions.
1 Copyright © 2004, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement.
Using the Set Operators
Using SQL*Plus.
Oracle : SQL.
Using the Set Operators
Trainer: Bach Ngoc Toan– TEDU Website:
Restricting and Sorting Data
Presentation transcript:

16 Copyright © Oracle Corporation, All rights reserved. Oracle9 i Datetime Functions

16-2 Copyright © Oracle Corporation, All rights reserved. Objectives After completing this lesson, you should be able use the following datetime functions: TZ_OFFSET CURRENT_DATE CURRENT_TIMESTAMP LOCALTIMESTAMP DBTIMEZONE SESSIONTIMEZONE EXTRACT FROM_TZ TO_TIMESTAMP TO_TIMESTAMP_TZ TO_YMINTERVAL

16-3 Copyright © Oracle Corporation, All rights reserved. TIME ZONES -08:00 The image represents the time for each time zone when Greenwich time is 12: :00 +02:00+10:00 +07:00

16-4 Copyright © Oracle Corporation, All rights reserved. Oracle9 i Datetime Support In Oracle9 i, you can include the time zone in your date and time data, and provide support for fractional seconds. Three new data types are added to DATE: –TIMESTAMP –TIMESTAMP WITH TIME ZONE (TSTZ) –TIMESTAMP WITH LOCAL TIME ZONE (TSLTZ) Oracle9 i provides daylight savings support for datetime data types in the server.

16-5 Copyright © Oracle Corporation, All rights reserved. Hidden Slide

16-6 Copyright © Oracle Corporation, All rights reserved. TZ_OFFSET SELECT TZ_OFFSET('US/Eastern') FROM DUAL; SELECT TZ_OFFSET('Canada/Yukon') FROM DUAL; SELECT TZ_OFFSET('Europe/London') FROM DUAL; Display the time zone offset for the time zone 'US/Eastern' Display the time zone offset for the time zone 'Canada/Yukon' Display the time zone offset for the time zone 'Europe/London'

16-7 Copyright © Oracle Corporation, All rights reserved. Hidden Slide

16-8 Copyright © Oracle Corporation, All rights reserved. CURRENT_DATE CURRENT_DATE is sensitive to the session time zone. The return value is a date in the Gregorian calendar. ALTER SESSION SET TIME_ZONE = '-8:0'; SELECT SESSIONTIMEZONE, CURRENT_DATE FROM DUAL; ALTER SESSION SET TIME_ZONE = '-5:0'; SELECT SESSIONTIMEZONE, CURRENT_DATE FROM DUAL; Display the current date and time in the session’s time zone. ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-YYYY HH24:MI:SS';

16-9 Copyright © Oracle Corporation, All rights reserved. CURRENT_TIMESTAMP ALTER SESSION SET TIME_ZONE = '-8:0'; SELECT SESSIONTIMEZONE, CURRENT_TIMESTAMP FROM DUAL; ALTER SESSION SET TIME_ZONE = '-5:0'; SELECT SESSIONTIMEZONE, CURRENT_TIMESTAMP FROM DUAL; Display the current date and fractional time in the session's time zone. CURRENT_TIMESTAMP is sensitive to the session time zone. The return value is of the TIMESTAMP WITH TIME ZONE datatype.

16-10 Copyright © Oracle Corporation, All rights reserved. LOCALTIMESTAMP ALTER SESSION SET TIME_ZONE = '-5:0'; SELECT CURRENT_TIMESTAMP, LOCALTIMESTAMP FROM DUAL; ALTER SESSION SET TIME_ZONE = '-8:0'; SELECT CURRENT_TIMESTAMP, LOCALTIMESTAMP FROM DUAL; Display the current date and time in the session time zone in a value of TIMESTAMP data type. LOCALTIMESTAMP returns a TIMESTAMP value, whereas CURRENT_TIMESTAMP returns a TIMESTAMP WITH TIME ZONE value.

16-11 Copyright © Oracle Corporation, All rights reserved. DBTIMEZONE and SESSIONTIMEZONE SELECT DBTIMEZONE FROM DUAL; SELECT SESSIONTIMEZONE FROM DUAL; Display the value of the database time zone. Display the value of the session's time zone.

16-12 Copyright © Oracle Corporation, All rights reserved. EXTRACT SELECT EXTRACT (YEAR FROM SYSDATE) FROM DUAL; SELECT last_name, hire_date, EXTRACT (MONTH FROM HIRE_DATE) FROM employees WHERE manager_id = 100; Display the YEAR component from the SYSDATE. Display the MONTH component from the HIRE_DATE for those employees whose MANAGER_ID is 100.

16-13 Copyright © Oracle Corporation, All rights reserved. TIMESTAMP Conversion Using FROM_TZ SELECT FROM_TZ(TIMESTAMP ' :00:00','3:00') FROM DUAL; Display the TIMESTAMP value ' :00:00' as a TIMESTAMP WITH TIME ZONE value. SELECT FROM_TZ(TIMESTAMP ' :00:00', 'Australia/North') FROM DUAL; Display the TIMESTAMP value ' :00:00' as a TIMESTAMP WITH TIME ZONE value for the time zone region 'Australia/North'

16-14 Copyright © Oracle Corporation, All rights reserved. SELECT TO_TIMESTAMP_TZ(' :00:00 -8:00', 'YYYY-MM-DD HH:MI:SS TZH:TZM') FROM DUAL; STRING To TIMESTAMP Conversion Using TO_TIMESTAMP and TO_TIMESTAMP_TZ SELECT TO_TIMESTAMP (' :00:00', 'YYYY-MM-DD HH:MI:SS') FROM DUAL; Display the character string ' :00:00' as a TIMESTAMP value. Display the character string ' :00:00 -8:00' as a TIMESTAMP WITH TIME ZONE value.

16-15 Copyright © Oracle Corporation, All rights reserved. Time Interval Conversion with TO_YMINTERVAL SELECT hire_date, hire_date + TO_YMINTERVAL('01-02') AS HIRE_DATE_YMININTERVAL FROM EMPLOYEES WHERE department_id = 20; Display a date that is one year two months after the hire date for the employees working in the department with the DEPARTMENT_ID 20

16-16 Copyright © Oracle Corporation, All rights reserved. Summary TZ_OFFSET FROM_TZ TO_TIMESTAMP TO_TIMESTAMP_TZ TO_YMINTERVAL CURRENT_DATE CURRENT_TIMESTAMP LOCALTIMESTAMP DBTIMEZONE SESSIONTIMEZONE EXTRACT In this lesson, you should have learned how to use the following functions:

16-17 Copyright © Oracle Corporation, All rights reserved. Practice 16 Overview This practice covers using the Oracle9 i datetime functions.

16-18 Copyright © Oracle Corporation, All rights reserved. Hidden Slide

16-19 Copyright © Oracle Corporation, All rights reserved. Hidden Slide

16-20 Copyright © Oracle Corporation, All rights reserved. Hidden Slide