I have a field next_repay_date
开发者_Python百科 as varchar2(11)
.
I need to get the date after 2 days.
Suppose I am having next_repay_date as 25-Sep-2011
as varchar2(11)
, I should get a result as 27-Sep-2011
Please suggest a solution?
Dates should not be held in char fields - use a Date or datetime
Then add two days - which I think is DBMS sepcific
Step 1, use the correct type for dates, that is, type DATE.
Step 2, use yourdate + INTERVAL 2 DAY (mysql).
Since you are using Oracle this could be done as
SELECT to_date('25-Sep-2007', 'dd-MON-RRRR') + 2 from dual
Date arithmetic is really simply in Oracle, providing we have an actual DATE to work with. So the first step is to cast your column to a DATE datatype, and then you can add or subtract days from it.
SQL> select to_date('27-SEP-2011', 'DD-MON-YYYY') + 2
2 from dual
3 /
TO_DATE('
---------
29-SEP-11
SQL>
精彩评论