SQL series (basic)-Chapter 1 about sysdate

Source: Internet
Author: User

Chapter 1 Basic SQL statements
1. query the database system time, which is usually displayed in the default format of the server (depending on the character set of the database );
Note: dual is a virtual table in the database and belongs to the Administrator sys user, but all users can access it. It has no practical significance, act only as the structure of the select statement (dual serves as the statement structure when the system information and temporary results are obtained using the select statement );

TYGER @ ORCL> select sysdate from dual;


SYSDATE
---------
18-jun14


1.1 modify the display format of the system time. (The session indicates that the modification is valid for the current session)
TYGER @ ORCL> alter session set nls_date_format = 'yyyy-mm-dd hh24: mi: ss ';


Session altered.


TYGER @ ORCL> select sysdate from dual;


SYSDATE
-------------------
16:11:37


1.2 add or subtract the system time;
1.2.1 add or subtract a number to indicate the number of days after the given time;
TYGER @ ORCL> select sysdate from dual;


SYSDATE
-------------------
16:11:37


TYGER @ ORCL> select sysdate + 2, sysdate-2 from dual; (2 days, 2 days ago)


SYSDATE-2 SYSDATE + 2
--------------------------------------
16:13:58 16:13:58


1.2.2 how many hours, minutes, And seconds are appended (2 hours, 2 minutes, and 2 seconds)
TYGER @ ORCL> select sysdate, sysdate + 2/24, sysdate + 2/24/60, sysdate + 2/24/60/60 from dual;


SYSDATE + 2/24 SYSDATE + 2/24/60 SYSDATE + 2/24/60/60
----------------------------------------------------------------------------
16:15:50 18:15:50 16:17:50


Note: The modification of the preceding time format is only valid for the current session;
Only temporary data is displayed and the original data values in the table are not changed.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.