SQL*Plus: Release 9.2.0.3.0 - Production on Wed Jul 30 21:45:18 2003
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Enter user-name: appdev@nick920
Enter password:
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production
With the Partitioning, Oracle Label Security, OLAP and Oracle Data Mining options
JServer Release 9.2.0.3.0 - Production
appdev@NICK920.US.ORACLE.COM> create table t
2 (name varchar2(30),
3 dob date)
4 /
Table created.
appdev@NICK920.US.ORACLE.COM> insert into t
2 values('nick','10-06-2001')
3 /
values('nick','10-06-2001')
*
ERROR at line 2:
ORA-01843: not a valid month
appdev@NICK920.US.ORACLE.COM> insert into t
2 values('nick','10-jun-01')
3 /
1 row created.
appdev@NICK920.US.ORACLE.COM> select months_between(sysdate,dob)
2 from t
3 where name like 'ni%'
4 /
MONTHS_BETWEEN(SYSDATE,DOB)
---------------------------
25.674471
appdev@NICK920.US.ORACLE.COM> /* or if you want in days, etc...*/
appdev@NICK920.US.ORACLE.COM>
appdev@NICK920.US.ORACLE.COM> select trunc(months_between(sysdate,dob)/12) years,
2 mod(trunc(months_between(sysdate,dob)),12) months,
3 sysdate - add_months(dob,trunc(months_between(sysdate,dob))) days
4 from t
5 where name like 'ni%'
6 /
YEARS MONTHS DAYS
---------- ---------- ----------
2 1 20.9149537
appdev@NICK920.US.ORACLE.COM>
Tarry Singh
I'm a JOLE(JavaOracleLinuxEnthusiast)
--- Everything was meant to be---
Bookmarks