Oracle obtains the current date and Date Format

Source: Internet
Author: User

Oracle obtains the current date and Date Format

Get system date: sysdate ()
Format Date: to_char (sysdate (), 'yy/MM/DD hh24: MI: SS)
Or to_date (sysdate (), 'yy/MM/DD hh24: MI: SS)
Format the number: to_number

Note: to_char converts a date or number to a string
to_char (number, 'formatting ')
to_char (salary,' $99,999.99 ')
to_char (date, 'format')

To_date converts a string to the date type in the database
To_date (char, 'format ')

To_number converts a string to a number.
To_number (char, 'format ')

Returns the system date. The value is 25-12-09.
Select sysdate from dual;
Mi is minute, output 14:23:31
Select to_char (sysdate, 'yyyy-mm-dd hh24: MI: ss') from dual;
Mm will display the month, output 14:12:31
Select to_char (sysdate, 'yyyy-mm-dd hh24: mm: ss') from dual;
Output: 09-12-25 14:23:31
Select to_char (sysdate, 'yy-mm-dd hh24: MI: ss') from dual
Output 14:23:31

Select to_date ('2017-12-25 14:23:31 ', 'yyyy-mm-dd, hh24: MI: ss') from dual
If you write the above:
Select to_date ('2017-12-25 14:23:31 ', 'yyyy-mm-dd, HH: MI: ss') from dual
An error is reported because the hour hh is in 12-digit format and 14 is invalid and cannot be matched.

Output $10,000, 00:
Select to_char (1000000, '$99,999, 99') from dual;
Output RMB10, 000,00:
Select to_char (1000000, 'l99, 999,99') from dual;
Output 1000000.12:
Select trunc (to_number ('192. 1000000 '), 2) from dual;
Select to_number ('192. 1000000 ') from dual;

Conversion format:

Y indicates the last digit of year,
YY indicates the last two digits of the year,
YYY indicates the last three digits of the Year,
Yyyy indicates the year in four digits

Month: mm represents month,
Mon can be abbreviated as November, Nov,
The full name of month, for example, January 1, November or November.

Dd indicates the day of the month,
Ddd indicates the day of the year,
The day of the week, short for Dy, such as Friday or Fri,
The day of the week, such as Friday or Friday.

Two-digit HH for hour indicates 12-digit hour,
Hh24 2-digit 24-hour

Indicates minute. MI 2-digit indicates minute.

Indicating Second: two-digit SS indicates 60 seconds

For a quarter: Q indicates a single digit for a quarter (1-4)

In addition, WW is used to indicate the week W of the current year to indicate the week W of the current month.

Time range in the 24-hour system: 00: 00: 00-23:59:59
Time range in the 12-hour format: 1: 00: 00-12:59:59

digit format: 9 indicates a number.
0 indicates 0.
$ place a $ character.
L place a floating local currency character.
. show decimal point
, display the thousands indicator

Supplement:
Current Time minus 7 minutes
Select sysdate, sysdate-interval '7' minute from dual;
Current Time minus 7 hours
Select sysdate-interval '7' hour from dual;
Current Time minus 7 days
Select sysdate-interval '7' day from dual;
Current Time minus July
Select sysdate, sysdate-interval '7' month from dual;
Current Time minus 7 years
Select sysdate, sysdate-interval '7' year from dual;
Time Interval multiplied by a number
Select sysdate, sysdate-8 * interval '7' hour from dual;

Description:
Dual pseudo Column
Dual is an existing table in Oracle that can be read by any user. It is often used in select statement blocks without a target table.
Different systems may return different date formats.
Returns the user of the current connection: Select User from dual;

 

Http://blog.csdn.net/ReturnMe/article/details/5822002

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.