sql - ORA-01722: invalid number - Subtracting Dates -


i have query i'm trying write/get run... can return results if further filters , add "rownum < 100". can keep increasing , expand results.. however, if remove , let run in entirety throws oracle sql error:

database error: 511 - ora-01722: invalid number

any appreciated!

select inventory_view.prtnum, inventory_view.lotnum, inventory_view.expire_dte,     inventory_view.mandte, to_number(inventory_view.expire_dte - inventory_view.mandte) "delta", substr(inventory_view.age_pflnam, 1, 3) "age profile", to_number((inventory_view.expire_dte - inventory_view.mandte)) - to_number(substr(inventory_view.age_pflnam, 1, 3)) "delta 2", lst_arecod, prt_client_id inventory_view inventory_view.prtnum = inventory_view.prtnum , lst_arecod <> 'ship' , prt_client_id = 'test' 

you're getting error because 1 of to_number conversions fails specific row , column. until hit row, not error, explains why and rownum < ... runs successfully.

to determine erring values, can try following query, tests values of columns, being converted, non-numeric values.

select      inventory_view.prtnum,      inventory_view.lotnum,      inventory_view.expire_dte,          inventory_view.mandte,      to_number(inventory_view.expire_dte - inventory_view.mandte) "delta",      substr(inventory_view.age_pflnam, 1, 3) "age profile",      to_number((inventory_view.expire_dte - inventory_view.mandte)) - to_number(substr(inventory_view.age_pflnam, 1, 3)) "delta 2",      lst_arecod,      prt_client_id select inventory_view.* inventory_view lst_arecod <> 'ship' , prt_client_id = 'test' ,  (lower(inventory_view.expire_dte) <> upper(inventory_view.expire_dte) or lower(inventory_view.mandte) <> upper(inventory_view.mandte) or lower(substr(inventory_view.age_pflnam, 1, 3)) <> upper(substr(inventory_view.age_pflnam, 1, 3)) ); 

also, can exclude these non-numeric values in original query, below:

select      inventory_view.prtnum,      inventory_view.lotnum,      inventory_view.expire_dte,          inventory_view.mandte,      to_number(inventory_view.expire_dte - inventory_view.mandte) "delta",      substr(inventory_view.age_pflnam, 1, 3) "age profile",      to_number((inventory_view.expire_dte - inventory_view.mandte)) - to_number(substr(inventory_view.age_pflnam, 1, 3)) "delta 2",      lst_arecod,      prt_client_id select inventory_view.* inventory_view lst_arecod <> 'ship' , prt_client_id = 'test' , lower(inventory_view.expire_dte) = upper(inventory_view.expire_dte) , lower(inventory_view.mandte) = upper(inventory_view.mandte) , lower(substr(inventory_view.age_pflnam, 1, 3)) = upper(substr(inventory_view.age_pflnam, 1, 3)); 

please note inventory_view.prtnum = inventory_view.prtnum condition has been removed since true.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -