Oracle date functions are used to process dates and times in an Oracle database, and the following is a detailed introduction to the use of Oracle date functions in the hope of enlightening you.
(1) Sysdate and trunc
Two Oracle
Oracle date functions are already available on the Internet. Let's focus on it to avoid your troubles.
Oracle date functions are already available on the Internet. Let's focus on it to avoid your troubles.
In the development of oracle databases, due to time issues, the week
SelectOper_time, Micropay, REFUND from ( Selecttrunc (oper_time) oper_time, class_name, sum (total_fee) Total_fee fromWx_pay_detail GROUP by Trunc (Oper_time), class_name) pivot (sum (total_fee) forClass_nameinch ('Micropay' as "Micropay",'Refund' as "REFUND") ) Order by Oper_time↑sql, post-conversion column names in for ... In as desired "name"Oracle according to the "
In the development of Oracle databases, due to time issues, the weekly chapter is too large, so the date functions of Oracle Data are specially added to favorites. It is for another day's query.
Add_months (d, n) date D plus N months
What month does last_day (d) contain D? The date
Oracle and Java date formats
If you want to convert to a 2005-07-05 format, you need to use the class SimpleDateFormat
SimpleDateFormat formatt= New SimpleDateFormat ("Yyyy-mm-dd");Date Date =new date ();System.out.println (Formatt.format (
Label:phenomenon : Students who have used Oracle in a multi-lingual environment must have encountered such a problem, Date_v date; Date_v: = to_date (' 2010/11/16 ');--or ' 2010/11/16 ' The same server, different Oracle clinet does not necessarily work. cause : Without specifying a conversion string,
database-level default format to modify the parameter file, and restart the database, but this also can not change your third-party tool display format, third-party tools can only be changed within the tool, it can only change the default date format, third-party tools are converted But many times easy to be fooled by the tool, give the feeling is that the database is so stored, in fact, only the date form
to modify the parameter file, and restart the database, but this will not change your Third-party tool display format, Third-party tools can only be changed within the tool, it can only change the default date format, the Third-party tools are converted , but many times it's easy to be fooled by tools, the feeling is that the database is stored in this way, in fact, only the date format stored, no yyyymm t
----------------- ----------------- ---------- ---------- ---------- ---------- ---------- 15 06202003:16:55:14 07082003:11:22:57 43 27 18 17 2 16 06262003:11:16:36 07082003:11:22:57 21 6 0 12 12. TIMESTAMP Data Type
The main problem with the DATE data type is that its granularity cannot determine which of the two events occur first. ORACLE has extended the TIMESTAMP data type in the
Oracle operations on time and date
Oracle time/date operations
There are many date functions in oracle, such:
1,Add_months ()Used to increase or decrease the number of months from a date
Detailed Connection: http://blog.163.com/lsj_start/blog/static/17826443920111112103716524/http://blog.itpub.net/29324876/viewspace-1096741/(view implicit conversion with explain)Oracle has three of the most basic data types, namely, character, numeric, and date. also provides a type conversion function1)To_char Numeri
Processing date in Oracle
To_date formatDay:Dd number 12Dy abbreviated FriDay spelled out FridayDdspth spelled out, ordinal twelfthMonth:MM number 03Mon abbreviated MARMonth spelled out MarchYear:YY two digits 98Yyyy four digits 1998
The time range in the 24-hour format is: 0:00:00-23:59:59 ....The time range in the 12-hour format is: 1:00:00-12:59:59 ....1.Date
Processing date in Oracle
To_date formatDay:Dd number 12Dy abbreviated FriDay spelled out FridayDdspth spelled out, ordinal twelfthMonth:MM number 03Mon abbreviated MARMonth spelled out MarchYear:YY two digits 98Yyyy four digits 1998
The time range in the 24-hour format is: 0:00:00-23:59:59 ....The time range in the 12-hour format is: 1:00:00-12:59:59 ....1.Date
, select 1 | '2' from dual;-> select to_char (1) | '2' from dual; 8) During arithmetic operations on and comparisons between characterand noncharacter datatypes, oracle converts from any character datatype to anumber, date, or Rowid, as appropriate. in arithmetic operations betweenCHAR/VARCHAR2 and NCHAR/NVARCHAR2, Oracle converts to a number. if data of the char
To_timestamp (' 2012-7-28 03:12:00 ', ' yyyy-mm-dd hh24:mi:ss ')-systimestamp from dualThe result: +000000092 05:51:24.032000000, a little intercept, you can get 92 days 5 hours, 51 minutes, 24 seconds, so users look more intuitive! But this number is not very intuitive for programmers, if you want a specific length of time, and the accuracy is not required to milliseconds, you can convert the timestamp type to date type, and then directly subtract.T
through index range scan. However, by default, oracle CBO does not select the index location. For example, oracle uses table full scan. Why? This type of problem occurs only when TIMESTAMP is introduced after oracle version 9.2.
Before 9.2, Oracle only had DATE, but not TIM
In the development of Oracle databases, it is often a matter of time, so the date function of Oracle data is collected specifically. is for future investigation.
Add_months (d,n) Date d plus n months
Last_day (d) The date of the last day of the month that contains D
New_time
There are many date functions in oracle, such:
1,Add_months ()Used to increase or decrease the number of months from a date value.
Date_value: = add_months (date_value, number_of_months)
Example:
SQL> select add_months (sysdate, 12) "Next Year" from dual;
Next Year
----------
April 11-04
SQL> select add_months (sysdate, 112) "Last Year" from dual;
Last Year
----
, you are looking for every Friday date in the first three months of the current month.9.oracle Medium Time operationThe contents are as follows:1, Oracle supports the operation of the date2, the date is calculated in days as a unit3, when it is necessary to calculate the value of smaller units, such as seconds, time-b
monthSelect To_char (T.D, ' Yy-mm-dd ') from (Select Trunc (sysdate, ' MM ') +rownum-1 as DFrom Dba_objectswhere RowNum where To_char (T.D, ' mm ') = To_char (sysdate, ' mm ')--Find the Friday date of the current monthand Trim (To_char (T.D, ' Day ')) = ' Friday '--------11-05-0211-05-0911-05-1611-05-2311-05-30If you change where To_char (T.D, ' mm ') = To_char (sysdate, ' mm ') to sysdate-90, you are looking for every Friday
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.