Click here to Skip to main content
15,909,030 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
when i run below query
Error occured.
SQL
SELECT 
  cast(substr(T_BILLSUMMARY.OPDNUMBER,1,6) as INTEGER) as OPD,
  substr(T_BILLSUMMARY.OPDNUMBER,8,12) as OPDYEAR,
  T_BILLSUMMARY.BILLTONAME
FROM T_BILLSUMMARY
where cast(substr(T_BILLSUMMARY.OPDNUMBER,1,6) as NUMBER)=10805;


Error Occurred

HTML
ORA-01722:invalid number


how can i solve this...???
Posted
Updated 25-Aug-14 21:37pm
v2
Comments
Magic Wonder 26-Aug-14 3:39am    
Make sure that as per Cast criteria string data should not come.

1 solution

Hi,

Try this....


SQL
SELECT
CASE WHEN length(translate(substr(T_BILLSUMMARY.OPDNUMBER,1,6),' +-.0123456789',' ')) > 0 
THEN 'Wrong Value'
ELSE cast(substr(T_BILLSUMMARY.OPDNUMBER,1,6) as INTEGER) 
END 
as OPD,
substr(T_BILLSUMMARY.OPDNUMBER,8,12) as OPDYEAR,
T_BILLSUMMARY.BILLTONAME
FROM T_BILLSUMMARY
where cast(substr(T_BILLSUMMARY.OPDNUMBER,1,6) as NUMBER)=10805;


Hope this will help you.

Cheers
 
Share this answer
 
v2
Comments
Magic Wonder 26-Aug-14 4:12am    
i think ISNUMERIC will not work in Oracle.
aftab5124 3-Sep-14 3:53am    
ORA-00932: inconsistent datatypes:expected char got number
Magic Wonder 3-Sep-14 3:59am    
If required use no as char.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900