31-DEC-95 not a string and is not 20-JUN-94 . These are numbers with the addition of additional material at the end. It should be '31-DEC-95' or '20-JUN-94' - mark single quote ' . This will allow you to perform string comparisons.
However, you are not comparing strings; you are doing a date comparison. You must convert the string to a date. Either using the built-in TO_DATE() function, or date literal .
TO_DATE ()
select employee_id from employee where employee_date_hired > to_date('31-DEC-95','DD-MON-YY')
This method has some unnecessary errors
- As noted in the comments of a_horse_with_no_name,
DEC does not necessarily mean December. It depends on the settings of NLS_DATE_LANGUAGE and NLS_DATE_FORMAT . To make sure that your comparison with work in any locale you can use the model of the format datetime MM instead - The year '95 is inaccurate. You know what you mean 1995, but what if it was 50 years old, is it 1950 or 2050? It is always better to be explicit.
select employee_id from employee where employee_date_hired > to_date('31-12-1995','DD-MM-YYYY')
Date literals
The date literal is part of the ANSI standard, which means that you do not need to use the special Oracle function. When using a literal, you must specify your date in the format YYYY-MM-DD , and you cannot include a time element.
select employee_id from employee where employee_date_hired > date '1995-12-31'
Remember that the Oracle date data type includes a time element, so a date without a time part is equivalent to 1995-12-31 00:00:00 .
If you want to enable the temporary part, you will have to use the timestamp literal, which accepts the format YYYY-MM-DD HH24:MI:SS[.FF0-9]
select employee_id from employee where employee_date_hired > timestamp '1995-12-31 12:31:02'
Additional Information
NLS_DATE_LANGUAGE obtained from NLS_LANGUAGE and NLS_DATE_FORMAT derived from NLS_TERRITORY . They are installed when you initially created the database, but you can change them by changing the initialization parameters file - only if it is really necessary - or at the session level using ALTER SESSION . For example:
alter session set nls_date_format = 'DD.MM.YYYY HH24:MI:SS';
It means:
DD numeric day of the month, 1 - 31MM numeric month of the year, 01 - 12 (January 01)YYYY 4-digit year - in my opinion, it is always better than a two-digit year YY , because there is no confusion with what century you mean.HH24 hour of the day, 0 - 23MI minute of an hour, 0 - 59SS second minutes, 0-59
You can find out your current language and date language settings by V$NLS_PARAMETERSs and the full gamut of valid values โโby V$NLS_VALID_VALUES .
Further reading
By the way, if you want count(*) , you need to group by employee_id
select employee_id, count(*) from employee where employee_date_hired > date '1995-12-31' group by employee_id
This gives you an account for employee_id .