Oracle gets 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 Number: To_number
Note: to_char Converts a date or number to a string
to_char (number, ' format ')
To_char (Salary, ' $99,999.99 ')
to_char (date, ' format ')
To_date converts a string to a date type in the database
To_date (char, ' format ')
To_number converts a string to a number
To_number (char, ' format ')
return system date, output 2 May-December-09
Select Sysdate from dual;
Mi is minute, output 2009-12-25 14:23:31
Select To_char (sysdate, ' Yyyy-mm-dd HH24:mi:ss ') from dual;
MM displays month, output 2009-12-25 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 2009-12-25 14:23:31
Select To_date (' 2009-12-25 14:23:31 ', ' Yyyy-mm-dd,hh24:mi:ss ') from dual
And if the upper-class writing:
Select To_date (' 2009-12-25 14:23:31 ', ' Yyyy-mm-dd,hh:mi:ss ') from dual
will be an error, because the hour HH is 12 into the system, 14 for illegal input, can not match.
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 (' 1000000.123 '), 2) from dual;
Select To_number (' 1000000.123 ') from dual;
Format of the conversion:
Represents the year's: Y represents the last one,
YY represents the last 2 digits of the year,
YYY says the last 3 digits of the year,
YYYY 4 digits for years
Indicates month: mm with 2 digits for month,
Mon in shorthand form, such as November or Nov,
Month with full name, such as November or November.
That represents day: DD represents the days of the month,
DDD indicates the first days of the year,
DY when Zhou Di a few days, abbreviated, such as Friday or Fri,
Day when Zhou Di a few days, full name, such as Friday or Friday
The hour: HH 2 digits indicates the hour 12 system,
Hh24 2 digits indicates an hour of 24 hours
Indicates minute: MI 2 digits for minutes
Representing second: SS 2 digits in seconds 60
That represents the quarter: Q A number for the quarter (1-4)
In addition, WW is used to indicate the first weeks of the year in which W is used to denote the week of the month.
Time range under 24-hour system: 00:00:00-23:59:59
Time range under 12-hour system: 1:00:00-12:59:59
Number format: 9 represents a number
0 Force display 0
$ Place a $ character
l Place a floating local currency character
. Show decimal point
, display thousand indicator
Add:
Current time minus 7 minutes of time
Select Sysdate,sysdate-interval ' 7 ' MINUTE from dual;
The current time minus 7 hours of time
Select Sysdate-interval ' 7 ' hour from dual;
The current time minus 7 days
Select Sysdate-interval ' 7 ' from dual;
Current time minus July time
Select Sysdate,sysdate-interval ' 7 ' month from dual;
The current time minus 7 years time
Select Sysdate,sysdate-interval ' 7 ' from dual;
Time interval multiplied by a number
Select Sysdate,sysdate-8*interval ' 7 ' hour from dual;
Meaning explanation:
Dual pseudo columns
Dual is an actual table in Oracle that can be read by any user and is often used in a SELECT statement block that does not have a target table.
Different systems may return dates in the same format.
Returns the current connected User: Select User from Dual;