Re: SQL Problem
"Tony Andrews" <[email protected]> Thu, 20 Feb 2003 10:42:04
| Newsgroups | gmane.comp.db.oracle.devel |
|---|---|
| Message-ID | <LYRIS-1796914-881793-2003.02.20-10.26.25--gcdod-oracle#[email protected]> |
> As a question and not really involved in this topic, would you not use to_date on a date if you only wanted the month portion or even the month/year portion? i.e. to_date(v.vtran_effective_date, 'Mon-YYYY'). No, you would use TO_CHAR(v.vtran_effective_date, 'Mon-YYYY') TO_DATE takes a DATE and converts it to a VARCHAR2 TO_CHAR takes a VARCHAR2 and converts it to a DATE Whenever you do TO_DATE(date_value) you are IMPLICITLY doing TO_DATE (TO_CHAR(date_value)), and the implicit TO_CHAR is done with the default format mask (e.g. DD-MON-YYYY). In fact, your example above will fail with the error "ORA-01843: not a valid month" - UNLESS your default format mask just happens to be 'MON-YYYY' also, which is very unlikely! You can also use TRUNC with a format mask on dates to return dates, e.g. TRUNC(sysdate,'MM') will return the DATE value 01-FEB-2003 TRUNC(sysdate,'YYYY') will return the DATE value 01-JAN-2003 --- Change your mail options at http://p2p.wrox.com/manager.asp or to unsubscribe send a blank email to [email protected].