I am using Oracle 8.1.6 on windows NT.
I have written following sql and getting error.. ORA-01722: Invalid number
SELECT emp_id,
CONCAT (
CONCAT (CONCAT (CONCAT (name_first, ' '), name_middle), ' '),
name_last
),
desig_des, t
FROM (SELECT emp_id, name_first, name_middle, name_last, desig_des, t
FROM ((SELECT h.emp_id, h.name_first, h.name_middle, h.name_last,
d.desig_des, 'Y' t
FROM ta_hr_empinf_m h, ta_hr_desig_m d
WHERE d.desig_id = h.desig_id
AND h.status = 'C'
AND h.emp_id NOT IN (SELECT emp_id
FROM ta_hr_att_m))
UNION
(SELECT h.emp_id, h.name_first, h.name_middle, h.name_last,
d.desig_des, 'N' t
FROM ta_hr_att_m a, ta_hr_empinf_m h, ta_hr_desig_m d
WHERE h.emp_id = a.emp_id
AND d.desig_id = h.desig_id
AND a.rel_ter_lett_iss = 'N'))
WHERE SUBSTR (emp_id, 0, 1) IN
('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'))
WHERE TO_NUMBER (emp_id) >= 0 AND TO_NUMBER (emp_id) <= 100
ORDER BY TO_NUMBER (emp_id)
Now if I change the sql statement as follows it returns desire rows...
SELECT emp_id,
CONCAT (
CONCAT (CONCAT (CONCAT (name_first, ' '), name_middle), ' '),
name_last
),
desig_des, t
FROM (SELECT emp_id, name_first, name_middle, name_last, desig_des, t
FROM ((SELECT h.emp_id, h.name_first, h.name_middle, h.name_last,
d.desig_des, 'Y' t
FROM ta_hr_empinf_m h, ta_hr_desig_m d
WHERE d.desig_id = h.desig_id
AND h.status = 'C'
AND h.emp_id NOT IN (SELECT emp_id
FROM ta_hr_att_m))
UNION
(SELECT h.emp_id, h.name_first, h.name_middle, h.name_last,
d.desig_des, 'N' t
FROM ta_hr_att_m a, ta_hr_empinf_m h, ta_hr_desig_m d
WHERE h.emp_id = a.emp_id
AND d.desig_id = h.desig_id
AND a.rel_ter_lett_iss = 'N'))
WHERE SUBSTR (emp_id, 0, 1) IN
('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
AND TO_NUMBER (emp_id) >= 0
AND TO_NUMBER (emp_id) <= 100)
ORDER BY TO_NUMBER (emp_id)
What would be the probable cause for giving error.
Suggestion required....
Rgds,
Bhombal
by: pratikroyPosted on 2004-04-26 at 03:13:15ID: 10916969
This seems to be a logical error. There is no syntactical error in your SELECT statements. Invalid Number Error is coming because you are using TO_NUMBER function on a field (which may not be a number).
If you try the following you would realise, how TO_NUMBER works :
SQL> select to_number('0abc') from dual;
select to_number('0abc') from dual
*
ERROR at line 1:
ORA-01722: invalid number
SQL> select to_number('01223') from dual;
TO_NUMBER('01223')
------------------
1223
Now, if you execute your first SQL, it would let you know the line number on which the error is there. You may be able to understand the cause after looking at that line number in particular. You have changed the brackets in your second query, which means that you filter out the records differently in your second query. And due to that reason, you are not getting the records that might cause problems if you use TO_NUMBER.
Hope this helps.