I have a table of data for company officials. I have to show who completed a year of work at the company.
The data type for the yearAdmission field: DATE (dd / mm / yy)
To extract the year you can use:
SELECT idFuncionario, nomeFuncionario, anoAdmissao, EXTRACT (YEAR FROM anoAdmissao) AS ano FROM Tfuncionario
If you want to select who is completing a year today you can use:
SELECT Tfuncionario.* WHERE Mod(Trunc(sysdate) - Tfuncionario.anoAdmissao, 365 ) = 0
Does it help?
select * from tfuncionario where anoAdmissao <= '2000/01/01' and anoAdmissao >= '1999/01/01';
where '1999/01/01'
the beginning of a date and '2000/01/01'
the end.
I can count the years, but I could not limit the date to be displayed for a year:
SELECT trunc((months_between(sysdate, to_date(f.ANOADMISSAO,'dd/mm/yy')))/12) AS idade
FROM tfuncionario f
The query will show every year.