-3

I am getting an error:

ORA-01858: a non-numeric character was found where a numeric was expected

while executing this code:

SELECT 
    user_id,
    user_name,
    employee_id,
    start_date,
    end_date,
    last_update_date,
    MAX (start_date) OVER (PARTITION BY f.employee_id) AS max_start_date,
    MAX (last_update_date) OVER (PARTITION BY f.employee_id) AS max_last_update_date
FROM 
    refadm.cg1_fnd_user f
WHERE 
    TO_DATE (SYSDATE, 'DD/MON/YY  HH:MI:SSAM') <=
          COALESCE (TO_DATE (f.end_date, 'yyyy-MM-dd'), SYSDATE + 1)
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Roly Singh
  • 27
  • 5

2 Answers2

3

Don't convert sysdate to a date -- it is already a date:

WHERE SYSDATE <= TO_DATE(f.end_date, 'yyyy-MM-dd') OR
      f.end_date IS NULL

You may still get the problem, depending on what f.end_date looks like. But the logic is at least simpler.

If f.end_date is only sometimes in yyyy-MM-dd format, then you can use regular expressions or a user-defined function to handle the invalid formats.

EDIT:

If end_date is in a different format, then use the correct format:

WHERE SYSDATE <= TO_DATE(f.end_date, 'DD/MM/YYYY') OR
      f.end_date IS NULL
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
0

If your string has format '3/26/2013' - you wrote a wrong format in to_date function. It should be TO_DATE (f.end_date,'MM-DD-YYYY') The whole sentence can look like

WHERE SYSDATE <= TO_DATE(f.end_date, 'MM-DD-YYYY') OR
      f.end_date IS NULL