CURSOR c_senior_employees is
SELECT first_name || ' ' || last_name as full_name, job_title, email, hire_date FROM employees
WHERE hire_date < date '2016-07-01'
ORDER BY hire_date, full_name;
I am using PLSQL and trying to fetch a DATE column with a cursor.
The SQL statement runs as expected, but an error occurs when I complied the cursor.
ORA-01861: literal does not match format string
I have tried using date literal in other formats (e.g. date '01-JUL-2016') and produces the same error. In addition, wrapping column "hire_date" with TO_DATE() function did not work for me. What did I do wrong here? Thanks in advance.
UPDATED: working code
CREATE OR REPLACE PROCEDURE P_employees
AS
CURSOR c_senior_employees is
SELECT first_name || ' ' || last_name as full_name, job_title, email, hire_date FROM employees
WHERE hire_date < date '2016-07-01'
ORDER BY hire_date, full_name;
CURSOR c_junior_employees is
SELECT first_name || ' ' || last_name as full_name, job_title, email, hire_date FROM employees
WHERE not hire_date < date '2016-07-01'
ORDER BY hire_date, full_name;
r_employee c_senior_employees%rowtype;
BEGIN
open c_senior_employees;
open c_junior_employees;
htp.p('<h1>Fake Employees</h1>');
htp.p('<p>Senior Employees</p>');
htp.p('<table border="1">');
htp.p('<tr>');
htp.p('<th>Employee Name</th>');
htp.p('<th>Job Title</th>');
htp.p('<th>Email</th>');
htp.p('<th>Hired on</th>');
htp.p('</tr>');
loop
fetch c_senior_employees into r_employee;
exit when c_senior_employees%notfound;
htp.p('<tr>');
htp.p('<td>' || r_employee.full_name || '</td>');
htp.p('<td>' || r_employee.job_title || '</td>');
htp.p('<td>' || r_employee.email || '</td>');
htp.p('<td>' || r_employee.hire_date || '</td>');
htp.p('</tr>');
end loop;
htp.p('</table>');
close c_senior_employees;
htp.p('<p>Junior Employees</p>');
htp.p('<table border="1">');
htp.p('<tr>');
htp.p('<th>Employee Name</th>');
htp.p('<th>Job Title</th>');
htp.p('<th>Email</th>');
htp.p('<th>Hired on</th>');
htp.p('</tr>');
loop
fetch c_junior_employees into r_employee;
exit when c_junior_employees%notfound;
htp.p('<tr>');
htp.p('<td>' || r_employee.full_name || '</td>');
htp.p('<td>' || r_employee.job_title || '</td>');
htp.p('<td>' || r_employee.email || '</td>');
htp.p('<td>' || r_employee.hire_date || '</td>');
htp.p('</tr>');
end loop;
htp.p('</table>');
close c_junior_employees;
END;