Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

to_number problem

569871Jun 17 2007 — edited Jun 17 2007
Hi:

I am running a query that uses the to_number function and I keep getting an "invalid number" error. It only happens when I use it in the WHERE clause, not in the select list. Here is the query:

SELECT
to_number(TRIM(SUBSTR(b.EventData, 16, LENGTH(RTRIM(b.EventData)) - 15))) AS strNumber,
LENGTH(TRIM(TRANSLATE(TRIM(SUBSTR(b.EventData, 16, LENGTH(RTRIM(b.EventData)) - 15)), ' +-.0123456789', ' '))) AS IsNumeric


FROM SYMP_sys_CBC_Staging_1 a, SYMP_sys_CBCStatWorking b
WHERE a.CallID = b.CallID
AND b.CallEventName = 'Network In Call Answered'
AND DATEDIFF('SS', a.Time_Arrived, b.CallEventTime) < 1800
AND DATEDIFF('SS', a.Time_Arrived, b.CallEventTime) >= 0
ORDER BY to_number(TRIM(SUBSTR(b.EventData, 16, LENGTH(RTRIM(b.EventData)) - 15)))
/*above works on its own*/
/*if I add this bit to the end it fails with "invalid number"*/
AND DATEDIFF('SS', a.Time_Arrived, b.CallEventTime) <=
to_number(TRIM(SUBSTR(b.EventData, 16, LENGTH(RTRIM(b.EventData)) - 15)))

So since I take off the last restriction it works fine with all values being converted to a number (confirmed by the second field returning NULL always), I am wondering whether the last WHERE clause doesn't get applied last--I would think it would being last in the list. That's the only reason I can think of--it I am applying it to the result set that works then it should not fail.

If it is not getting applied last then maybe it is testing against values that are not in the result set that works? (BTW DATEDIFF I created as a function)

Thanks,
Kayda
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 15 2007
Added on Jun 17 2007
2 comments
532 views