SQL Series (Basic)-chapter I about sysdate

Source: Internet
Author: User

Chapter I. BASIC SQL statements
1. Query the database system time, often in the server default format for display (depending on the database character set);
Note: Dual is a virtual table in the database, belonging to the Administrator sys user, but all the users can access, no practical meaning, only as the structure of the SELECT statement (with Select to System Information, temporary results, etc., with dual as the statement structure);

[Email protected]>select sysdate from dual;


Sysdate
---------
18-jun-14


1.1 Modify the display format of the system time; (session indicates that this modification is valid for the current session)
[Email protected]>alter session Set nls_date_format= ' Yyyy-mm-dd hh24:mi:ss ';


Session altered.


[Email protected]>select sysdate from dual;


Sysdate
-------------------
2014-06-18 16:11:37


1.2 The system time is added and reduced;
1.2.1 A number to indicate how many days will be added to the given time;
[Email protected]>select sysdate from dual;


Sysdate
-------------------
2014-06-18 16:11:37


[Email protected]>select sysdate+2,sysdate-2 from dual; (2 days, 2 days ago)


Sysdate+2 SYSDATE-2
------------------- -------------------
2014-06-20 16:13:58 2014-06-16 16:13:58


1.2.2 How many hours, how many minutes, how many seconds, (2 hours, 2 minutes, 2 seconds)
[Email protected]>select sysdate,sysdate+2/24,sysdate+2/24/60,sysdate+2/24/60/60 from dual;


Sysdate sysdate+2/24 sysdate+2/24/60 SYSDATE+2/24/60/60
------------------- ------------------- ------------------- -------------------
2014-06-18 16:15:50 2014-06-18 18:15:50 2014-06-18 16:17:50 2014-06-18 16:15:52


Note: Changes to the above time format are valid for the current session;
The resulting results are only temporary data to display, and will not change the data values in the table

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.