I am trying to find the max project code in a table using project codes and a customer code like so
SELECT DISTINCT Max(to_number(translate(substr(proj_code,7),'0123456789','0123456789')))
FROM
proj_ca
WHERE
proj_code LIKE 'CUST43_%'
AND cust_code = 'CUST';
This code is supposed to return 97 When I run this code i get ORA-01722 invalid number, however when I do 42 or 44 it returns the proper number. I'm not sure why the "to_number" is throwing an error.
I have narrowed it down to the "to_number" part. If I remove that it returns 97 without any issues.
CUST4397but sort before it - i.e. what do you see without the max? - Alex Pooletranslatesupposed to do? The way you wrote it, it does absolutely nothing. I imagine you think it does something, and perhaps that's the issue (or one issue, anyway). - mathguyto_numberhas been extended so it can handle conversion errors much better. - Boneist