oracle中日期格式问题

[size=medium]比如我从表中拿到A列为生日,其格式为varchar2类型,我想只要它的年,该如何操作?
如:select A from table;
A列输出结果为2010-10-26 为varchar2类型的,我只想要年,因为我要计算他的年龄![/size]

[code="java"]
select to_number(to_char(sysdate,'YYYY')-substr(t.A,1,4)) "年龄" from table t;
[/code]
直接帮你查出年龄算了

select to_date(A,'yyyy') from table;

select to_char(to_date(A,'yyyy-mm-dd'),'yyyy') from table;

那直接截取日期字符串
select substr(A,1,4) from table;

不好意思,那个有问题的~
select to_number(substr(A,0,4)) year from table;

如果你直接就想把字符串中的年取出用字符串截取就行,直接,方便,也不用在变成日期了。
select substr(a,1,4) from table;

select to_char(join_date,'yyyy') from employee;

其实这样是挺好的,没有日和月的,你试过了吗~
[quote]select to_char(to_date(A,'yyyy-MM-dd'),'yyyy') from table;[/quote]

如果要计算再转一下
[code="SQL"]select to_number(to_char(to_date(A,'yyyy-MM-dd'),'yyyy')) from table;[/code]