Subquery, TO_NUMBER and ORA-01722 invalid number
I'm running into a invalid number error (ORA-01722) when I expect none.
I have a table that stores a semester term as a VARCHAR2, all term codes are actually numbers like 200609. There is one exception which I filter out, using a subquery, to prevent the invalid number error.
My query looks like this:
SELECT NVL(SUM(s.balance))
FROM (SELECT s1.term, s1.balance
FROM student_account s1
WHERE s1.student_id = :student_id
AND s1.term <> 'SCRIPT') s
WHERE TO_NUMBER(s.term) <= 200609;
The query errors with ORA-01722.
Now I've checked and rechecked that there isn't another bad term that is not a number.
SELECT DISTINCT '[' || term || ']'
FROM student_account
WHERE student_id = :student_id;
The error complains at line of the WHERE clause.
I've ran just the subquery and changed the column list to select distinct term. All terms are numbers. I think that the outer WHERE clause for some reason still gets the 'SCRIPT' term. Though I've tried to verify this with no luck.
I created a function that simply takes the term writes it to DBMS_OUTPUT and returns it as a VARCHAR2. The weird thing is then the query works. For example the outer WHERE clause becomes: WHERE TO_NUMBER(PRINT_TERM(s.term)) <= 200609
I've also tried to move the TO_NUMBER to the subquery without any luck, same error.
Anyone know what is going on?
Oracle is allowed to push predicates into the subquery, so there is no guarantee that the problem row is filtered out before TO_NUMBER is called. You can get into some very interesting discussions about whether this is the right behavior from a relational theory and/or ANSI standard perspective, but you're probably stuck with the behavior (unless you want to get Oracle to rework their optimizer)
One way to get around the problem would be to write a my_to_number function that catches the error and returns NULL if the to_number conversion fails, i.e.
CREATE FUNCTION my_to_number( p_num IN VARCHAR2 )
RETURN NUMBER
IS
l_num number;
BEGIN
l_num := to_number( p_num );
RETURN l_num;
EXCEPTION
WHEN <<Exception whose name escapes me>> THEN
RETURN NULL;
END;And use that in your query.
Justin
Message was edited by:
Justin Cave
Similar Messages
-
TO_NUMBER and ORA-01722 invalid number pls delete
I cannot see where to delete a post I made. I found out my problem. It was in my NLS settings. Decimals were set to be commas instead of periods.
please disregard this post, and delete if you are a moderator
I recently tried to bring in lat/long coordinates from a VARCHAR2 field (and even as a flat file) into a NUMBER field with a setup of NUMBER(20,13) to ensure I'd capture all of the signifigant digits.
I even ran this through a procedure to check if the data is a number first, and update only. I've found however that I keep getting the ORA-01722 invalid number error.
So I started testing out some points, and came across this:
select to_number('-79.662965387') from dual;
this query results in the invalid number error. I don't want to have to load these as an SDO GEOMETRY object, has anyone encountered this scenario before?
Or is my choice of 13 decimal places too high for Oracle?I just ran that code in my database (10g) and it returned this
select to_number('-79.662965387') from dual;
TO_NUMBER('-79.662965387')
-79.662965
1 row selected.Message was edited by:
Tridith -
User Accounts and ORA-01722: invalid number error
Hello,
I have been using Express for a month or so now but have very limited knowledge of how it works.
My Problem:
I have a listing screen for user records which creates records in table QAS_USERS.
When I add a record it saves the data OK and put the record in the list.
When I click on the record in the list it takes me to the edit screen and I can change
the details and it works OK and all the changes get saved to the database.
On the data entry screen I have a list of the User Groups so I can select what group
the user will be in, usual details in username, fullname, email address, password etc..
I then added a routine to create a USER in the APEX Manage USERs.
It creates the record in my table QAS_USERS and it creates a APEX User Account with
the correct details and the record is displayed in the list.
So far so good.
Now the errors start:
1. When I look at the User Account in Administration -> Manage Application Express Users
most of the details have been added but the User Group does not get allocated.
2. The record I created in QAS_USERS appears in the list on my listing screen but when
I click on the Edit Icon on the left of the list I get the following error appear
when the screen changes to the edit screen:
ORA-01722: invalid number
Unable to fetch row error
QAS_USER Table:
ID NUMBER
CREATED_ON DATE
CREATED_BY VARCHAR2(10)
CHANGED_ON DATE
CHANGED_BY VARCHAR2(10)
ACTIVE VARCHAR2(3)
USERNAME VARCHAR2(10)
FULLNAME VARCHAR2(30)
TEAMLEADER VARCHAR2(3)
TEAMLEADER_ID NUMBER
LAB NUMBER
DIRECTOR VARCHAR2(3)
ACTION_MANAGER VARCHAR2(3)
SDM VARCHAR2(3)
GM VARCHAR2(3)
EMAIL_ADDRESS VARCHAR2(50)
PASSWORD VARCHAR2(12)
SDTL VARCHAR2(3)
FIRSTNAME VARCHAR2(30)
LASTNAME VARCHAR2(30)
GROUP_ID NUMBER
USER_ID VARCHAR2(20)
Process Script to create the Express User Account:
Declare
group_id NUMBER;
BEGIN
group_id := APEX_UTIL.get_group_id (:P15_GROUP_ID);
APEX_UTIL.CREATE_USER (
P_USER_NAME => :P15_USERNAME,
P_FIRST_NAME => :P15_FIRSTNAME,
P_LAST_NAME => :P15_LASTNAME,
P_WEB_PASSWORD => :P15_PASSWORD,
P_EMAIL_ADDRESS => :P15_EMAIL_ADDRESS,
p_developer_privs => 'ADMIN',
p_group_ids => group_id);
END;
If any one has any ideas I would be very grateful.
Regards,
Simon.Hi,
It could be that this is because you are using SYSDATE which contains the time as a fraction rather than TRUNC(SYSDATE) which just contains the current time. It could be that your working_dates_between raises this error.
However, your formula is far more complicated than it needs to be.
Firstly, you want to look at the date window ADD_MONTHS(TRUNC(SYSDATE), -6) to TRUNC(SYSDATE). Then you want to look at the portion of the absence that falls in the date window. This is GREATEST(Absence Attendance.Actual Start Date, ADD_MONTHS(TRUNC(SYSDATE), -6)) to LEAST(NVL(Absence Attendance."Actual End Date",TRUNC(SYSDATE)), TRUNC(SYSDATE)). You may need to add 1 to the absence end date because this is the last day of their absence rather than the date they return. It depends how you calculate the days between the start and end
date of the absence. You can create calculations for the start and end date of the absences within the 6 months time window. Create calculation AbsenceStart as
GREATEST(Absence Attendance.Actual Start Date, ADD_MONTHS(TRUNC(SYSDATE), -6))
and AbsenceEnd as
LEAST(NVL(Absence Attendance."Actual End Date",TRUNC(SYSDATE)), TRUNC(SYSDATE))
Then you need to only pick up absence that a part of the absence in your 6 month date window. You can use a condition in the workbook or a condition in a case statement to do this. You then need to calculate the difference between these dates and SUM all the values.
SUM(CASE WHEN AbsenceEnd >= AbsenceStart THEN WORKING_DAYS_BETWEEN(AbsenceStart, AbsenceEnd) END)
That's it. Not so complicated after all.
Rod West -
Case When Statement and ORA:01722 Invalid number error
Hi folks, I have posted this under another heading as well under E-business suite so apologies if some you have already seen it but I would really appreciate some help on this one. Any suggestions are most welcome.
We are trying to put together a calculation that returns the number of days absent an individual has had in a given time period. We need to cater for those absences that started before the period and are closed during it, absence that start during the period and end after it, and those that open and close within it.
The period is always a rolling 6 months from sysdate.
This is the calc we have come up with so far which works for some people but we get the invalid number error if the absence includes a half day - so 0.5, 1.5,etc.
This is probably over complicated but we are not techie at all so are learning as we go!
We are using the HRMS - Administration - Oracle Human Resources (Core) business area in 10G and the Absence Attendance and Person folders.
SUM(TO_NUMBER(NVL(( CASE WHEN Absence Attendance.Actual Start Date < TO_DATE(ADD_MONTHS(SYSDATE,-6),'DD-Mon-YYYY') THEN ( CASE WHEN Absence Attendance."Actual End Date" > SYSDATE THEN ( WORKING_DAYS_BETWEEN(TO_DATE(ADD_MONTHS(SYSDATE,-6),'DD-Mon-YYYY'),SYSDATE) ) ELSE ( CASE WHEN ( CASE WHEN TO_DATE(ADD_MONTHS(SYSDATE,-6),'DD-Mon-YYYY') >= Absence Attendance.Actual Start Date THEN ( WORKING_DAYS_BETWEEN(TO_DATE(ADD_MONTHS(SYSDATE,-6),'DD-Mon-YYYY'),Absence Attendance."Actual End Date") ) ELSE ( CASE WHEN ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,Absence Attendance."Actual End Date") ) IS NULL THEN ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,SYSDATE) ) ELSE ( CASE WHEN SYSDATE <= Absence Attendance."Actual End Date" THEN ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,SYSDATE) ) ELSE ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,Absence Attendance."Actual End Date") ) END ) END ) END ) IS NULL THEN ( WORKING_DAYS_BETWEEN(TO_DATE(ADD_MONTHS(SYSDATE,-6),'DD-Mon-YYYY'),SYSDATE) ) ELSE ( CASE WHEN TO_DATE(ADD_MONTHS(SYSDATE,-6),'DD-Mon-YYYY') >= Absence Attendance.Actual Start Date THEN ( WORKING_DAYS_BETWEEN(TO_DATE(ADD_MONTHS(SYSDATE,-6),'DD-Mon-YYYY'),Absence Attendance."Actual End Date") ) ELSE ( CASE WHEN ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,Absence Attendance."Actual End Date") ) IS NULL THEN ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,SYSDATE) ) ELSE ( CASE WHEN SYSDATE <= Absence Attendance."Actual End Date" THEN ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,SYSDATE) ) ELSE ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,Absence Attendance."Actual End Date") ) END ) END ) END ) END ) END ) ELSE ( CASE WHEN ( CASE WHEN TO_DATE(ADD_MONTHS(SYSDATE,-6),'DD-Mon-YYYY') >= Absence Attendance.Actual Start Date THEN ( WORKING_DAYS_BETWEEN(TO_DATE(ADD_MONTHS(SYSDATE,-6),'DD-Mon-YYYY'),Absence Attendance."Actual End Date") ) ELSE ( CASE WHEN ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,Absence Attendance."Actual End Date") ) IS NULL THEN ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,SYSDATE) ) ELSE ( CASE WHEN SYSDATE <= Absence Attendance."Actual End Date" THEN ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,SYSDATE) ) ELSE ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,Absence Attendance."Actual End Date") ) END ) END ) END ) IS NULL THEN ( WORKING_DAYS_BETWEEN(TO_DATE(ADD_MONTHS(SYSDATE,-6),'DD-Mon-YYYY'),SYSDATE) ) ELSE ( CASE WHEN TO_DATE(ADD_MONTHS(SYSDATE,-6),'DD-Mon-YYYY') >= Absence Attendance.Actual Start Date THEN ( WORKING_DAYS_BETWEEN(TO_DATE(ADD_MONTHS(SYSDATE,-6),'DD-Mon-YYYY'),Absence Attendance."Actual End Date") ) ELSE ( CASE WHEN ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,Absence Attendance."Actual End Date") ) IS NULL THEN ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,SYSDATE) ) ELSE ( CASE WHEN SYSDATE <= Absence Attendance."Actual End Date" THEN ( WORKING_DAYS_BETWEEN(Absence Attendance.Actual Start Date,SYSDATE) ) ELSE ( Absence Attendance.Duration Days ) END ) END ) END ) END ) END ),( DAYS_BETWEEN(Absence Attendance.Actual Start Date,Absence Attendance."Actual End Date") )),'999999990D00'))Hi,
It could be that this is because you are using SYSDATE which contains the time as a fraction rather than TRUNC(SYSDATE) which just contains the current time. It could be that your working_dates_between raises this error.
However, your formula is far more complicated than it needs to be.
Firstly, you want to look at the date window ADD_MONTHS(TRUNC(SYSDATE), -6) to TRUNC(SYSDATE). Then you want to look at the portion of the absence that falls in the date window. This is GREATEST(Absence Attendance.Actual Start Date, ADD_MONTHS(TRUNC(SYSDATE), -6)) to LEAST(NVL(Absence Attendance."Actual End Date",TRUNC(SYSDATE)), TRUNC(SYSDATE)). You may need to add 1 to the absence end date because this is the last day of their absence rather than the date they return. It depends how you calculate the days between the start and end
date of the absence. You can create calculations for the start and end date of the absences within the 6 months time window. Create calculation AbsenceStart as
GREATEST(Absence Attendance.Actual Start Date, ADD_MONTHS(TRUNC(SYSDATE), -6))
and AbsenceEnd as
LEAST(NVL(Absence Attendance."Actual End Date",TRUNC(SYSDATE)), TRUNC(SYSDATE))
Then you need to only pick up absence that a part of the absence in your 6 month date window. You can use a condition in the workbook or a condition in a case statement to do this. You then need to calculate the difference between these dates and SUM all the values.
SUM(CASE WHEN AbsenceEnd >= AbsenceStart THEN WORKING_DAYS_BETWEEN(AbsenceStart, AbsenceEnd) END)
That's it. Not so complicated after all.
Rod West -
Recieving ORA-01722 invalid number error while creating a materialized view
Hi,
I am receiving a ORA-01722 invalid number error while creating a materialized view. when run the select statement of the view i don't get any error, but when i use the same select statement to create a materialized view i receive this error. Could any please help in resolving this error. Here is the code i am using to create a materialized view.
CREATE MATERIALIZED VIEW MV_EBS_CH_CLOSED
REFRESH FORCE ON DEMAND
AS
SELECT DISTINCT kr.request_id, org.org_unit_name,
ebs_ch_ticket_type (kr.request_id) ticket_type,
DECODE
(kr.status_code,
'CLOSED_SUCCESS', kr.last_update_date,
'IN_PROGRESS', (SELECT MAX (start_time)
FROM ebs_ch_datastore ecd1
WHERE kr.request_id = ecd1.request_id
AND workflow_step_name =
'Final BA Review and Deployment Exit Criteria')
) closed_date,
substr(krhd.visible_parameter12,1,10) siebel_start_date,
kr.creation_date itg_start_date
FROM kcrt_requests kr,
kcrt_request_types krt,
kcrt_req_header_details krhd, kcrt_request_details krd1,
(SELECT koum.user_id user_id,
DECODE (koup.org_unit_name,
'IT Implementations', 'CHS - Service Management BA',
koup.org_unit_name
) org_unit_name
FROM krsc_org_unit_members koum, krsc_org_units koup
WHERE 1 = 1
AND 'Y' = koup.enabled_flag
AND koum.org_unit_id = koup.org_unit_id
AND EXISTS (
SELECT 'X'
FROM krsc_org_units kouc
WHERE koup.org_unit_id = kouc.org_unit_id
START WITH kouc.parent_org_unit_id =
ANY (SELECT org_unit_id
FROM krsc_org_units krsc_org_units1
WHERE 'Clearinghouse' =
org_unit_name)
CONNECT BY kouc.parent_org_unit_id =
PRIOR kouc.org_unit_id)
UNION
SELECT kou.manager_id user_id,
DECODE
(kou.org_unit_name,
'IT Implementations', 'CHS - Service Management BA',
kou.org_unit_name
) org_unit_name
FROM krsc_org_units kou
WHERE 'Y' = kou.enabled_flag
START WITH kou.parent_org_unit_id =
(SELECT org_unit_id
FROM krsc_org_units krsc_org_units2
WHERE 'Clearinghouse' = org_unit_name)
CONNECT BY kou.parent_org_unit_id = PRIOR kou.org_unit_id) org
WHERE krt.request_type_id = kr.request_type_id
AND krt.request_type_name IN ('Bug Fix', 'IT Enhancement')
and kr.REQUEST_ID = krd1.request_id
and krd1.batch_number = 1
AND kr.request_id = krhd.request_id
AND org.user_id in (krd1.parameter4, krd1.parameter5, krd1.parameter7)
AND ( 'CLOSED_SUCCESS' = kr.status_code
OR 'IN_PROGRESS' = kr.status_code
AND kr.request_id IN (
SELECT request_id
FROM (SELECT DISTINCT request_id,
MAX
(start_time)
closed_date
FROM ebs_ch_datastore
WHERE 'Final BA Review and Deployment Exit Criteria' =
workflow_step_name
GROUP BY request_id))
Thanks,
Shaik MohiuddinThis error occurs when you try to create a materialized view , but if you run the sql the results are perfectly fine. Well it happend to me also and to fix this I made sure all the coulmns have the same data type which are used in joins or in where clause.
use
where
to_number(col1)=to_number(col2) and to_number(col3)=to_number(col4)
hope this helps.. -
Varchar to number returns a ORA-01722-Invalid Number error
I have a script where i am converting a varchar to number to be compared against a number.
(To_Number(p.result_value,'999999.99') < 0 OR p.result_value < 0)
this particular line is causing the error ORA-01722-Invalid Number.
Is there any ideas as to why this happens and how I can resolve?
Thanks in advance!The result_value column in Pay_Run_Result_Values is a varchar2 field.
So you need to put in some additional logic to make sure that the row is having numbers alone before doing to_number.
Cheers
Ganesh -
ORA-01722: invalid number error coming in Oracle 10g.
Hi,
We are getting the error "ORA-01722: invalid number" while opening a cursor using CURSOR FOR LOOP.
This error has started coming only after we have migrated to Oracle 10g from Oracle 9i. Earlier the same code used to work properly. And also on Oracle 10g, its not happening every time. Sometimes it gives error while sometimes it works.
Does anybody know about any such bug in Oracle 10g. Our cursor is a parametrized cursor accepting a VARCHAR2 parameter and the value we are passing to it is also character.
Our database is Oracle 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production and is running on UNIX server.And also on Oracle 10g, its not happening every time. Sometimes it gives error while sometimes it works. This is typically due to
a) environment settings that differ from session to session
b) or more often, data
The actual error means that Oracle expects a number and is unable to obtain a number from the input (data or SQL or bind variables) supplied. I agree with William that it looks a lot like an implicit TO_NUMBER() conversion failing.
Why not add a debug exception handler to the code? When that exception occurs, dump the PL/SQL call stack and values of all variables and parameters to a debug/logging table (using an autonomous transaction). -
Oracle SQL Developer 1.1.1.25.14, I rror ORA-01722 Invalid Number
I have installed the new version of Oracle SQL Developer 1.1.1.25.14, I use Oracle 9.2. When I browse in the tree of the stored procedures and compile I obtain Error ORA-01722 Invalid Number. The previous version does not give this error. I have tried to change the decimal separator to comma ',' and point '.' but this error always appears.
create or replace
PROCEDURE getAge (
dtmDataStart_in IN DATE,
dtmDataEnd_in IN DATE,
intYears_out OUT NUMBER,
intMonths_out OUT NUMBER,
intDays_out OUT NUMBER) AS
-- Calcola il numero di anni, mesi, giorni intercorsi
-- dalla data iniziale alla data finale.
-- Se la data iniziale è > della data finale, le due date
-- vengono scambiate e le variabili di output vengono ritornate
-- con segno negativo.
--==================================================
-- Data Ultima Modifica: 31/07/98
-- Aggiunta procedura per il calcolo della differenza tra
-- due date dello stesso anno.
--==================================================
-- DICHIARAZIONE VARIABILI INIZIO --------------------------------------------------------
intYMDStart NUMBER(10);
intYMDEnd NUMBER(10);
intYMD NUMBER(10);
intDiffAnni NUMBER(5);
intDiffMesi NUMBER(5);
intDiffGiorni NUMBER(5);
intMeseStart NUMBER(5);
intAnnoStart NUMBER(5);
intTotGiorniMeseStart NUMBER(5);
ysnNegativo NUMBER(5);
-- DICHIARAZIONE VARIABILI FINE ----------------------------------------------------------
BEGIN
intYMDStart := TO_NUMBER( TO_CHAR(dtmDataStart_in,'YYYYMMDD'));
intYMDEnd := TO_NUMBER( TO_CHAR(dtmDataEnd_in,'YYYYMMDD'));
ysnNegativo := 0;
IF intYMDStart = intYMDEnd THEN
intYears_out := 0;
intMonths_out := 0;
intDays_out := 0 ;
ELSE
IF intYMDStart > intYMDEnd THEN
intYMD := intYMDStart;
intYMDStart := intYMDEnd;
intYMDEnd := intYMD;
ysnNegativo := -1;
END IF;
intDiffAnni := TO_NUMBER(TO_CHAR(dtmDataEnd_in,'YYYY')) - TO_NUMBER(TO_CHAR(dtmDataStart_in ,'YYYY'));
intDiffMesi := TO_NUMBER(TO_CHAR(dtmDataEnd_in,'MM')) - TO_NUMBER(TO_CHAR(dtmDataStart_in ,'MM'));
intDiffGiorni := TO_NUMBER(TO_CHAR(dtmDataEnd_in,'DD')) - TO_NUMBER(TO_CHAR(dtmDataStart_in ,'DD'));
-- I valori cosi' calcolati di intDiffAnni, intDiffMesi e intDiffGiorni vanno bene
-- ad eccezione dei seguenti casi:
-- Sistemo intDiffAnni
IF (intDiffMesi > 0 OR (intDiffMesi = 0 AND intDiffGiorni >= 0)) THEN
-- intDiffAnni e' OK
intDiffAnni := intDiffAnni;
ELSE
-- non e' ancora arrivato il giorno del compleanno
intDiffAnni := intDiffAnni-1;
END IF;
-- Sistemo intDiffMesi
IF (intDiffMesi > 0 AND intDiffGiorni < 0) THEN
intDiffMesi := intDiffMesi-1;
ELSIF (intDiffMesi < 0 ) THEN
if(intDiffGiorni<0) THEN
intDiffMesi := intDiffMesi+11;
else
intDiffMesi := intDiffMesi+12;
END IF;
ELSIF (intDiffMesi=0 AND intDiffGiorni<0) THEN
intDiffMesi:=11;
END IF;
-- Sistemo intDiffGiorni
-- Calcolo i giorni come (TotGiorniMeseIniziale - GiornoIniziale) + (GiornoFinale - 0)
-- che e' uguale a fare TotGiorniMeseIniziale + (GiornoFinale-GiornoIniziale)
IF intDiffGiorni < 0 THEN
intMeseStart := TO_NUMBER(TO_CHAR(dtmDataStart_in ,'MM'));
IF intMeseStart IN (1,3,5,7,8,10,12) THEN
intTotGiorniMeseStart := 31;
ELSIF intMeseStart = 2 THEN
-- Da enciclopedia: sono bisestili gli anni multipli di 4
-- esclusi i secoli che non sono multipli di 400 (Parte commentata).
intAnnoStart := TO_NUMBER(TO_CHAR(dtmDataStart_in ,'YYYY'));
if (intAnnoStart MOD 4) = 0
-- AND NOT ((intAnnoStart MOD 100) = 0 AND (intAnnoStart MOD 400) <> 0)
Then
intTotGiorniMeseStart := 29;
else
intTotGiorniMeseStart := 28;
end if;
ELSIF intMeseStart IN (4,6,9,11) THEN
intTotGiorniMeseStart := 30;
END IF;
intDiffGiorni := intDiffGiorni + intTotGiorniMeseStart;
END IF;
IF ysnNegativo = 0 THEN
intDays_out := intDiffGiorni;
intMonths_out := intDiffMesi;
intYears_out := intDiffAnni;
ELSE
intDays_out := intDiffGiorni * (-1);
intMonths_out := intDiffMesi * (-1);
intYears_out := intDiffAnni * (-1);
END IF;
END IF;
EXCEPTION
WHEN OTHERS THEN
RAISE;
END getAge;
The output result of compilation is "GETAGE Compiled", I think the 01722 error is not caused from an sql syntax error, but probably caused from an invalid or unsupported or 'strange' configuration on nationalization... the fact surprises me that the previous version did not give problems
THANKS SO MUTCH
*/ -
ORA-01722: invalid number when performing query
Hi,
I am running SQL Developer on a laptop (XP Pro) accessing Oracle Applications
Product Version 11.5.10.2
Platform IBM SP AIX
OS Version AIX
Database 9.2.0.7.0
Support ID 14460365
If I run the following query it works fine -
select
mtrh.request_number
,to_number(mtrh.request_number)
from
mtl_txn_request_headers mtrh
where
to_number(mtrh.request_number) = 135060
and mtrh.request_number = '135060' -- works with this line in!!!!
however if I comment out the last line I get
An error was encountered performing the requested operation :
ORA-01722: invalid number
The field request_number is defined as varchar2(30)
It seems that there is something strange about the way it handles to_number in where clauses.
Thanks
Mick SulleyYou have an invalid number in request_number. If you add "and mtrh.request_number = '135060' ", the result set will be reduced to only those rows which have 135060 in the column and the to_number() will work. WIthout that row, it does to_number(request_number) for all rows in order to identify the one you want. When it comes across a request_number column which contains an invalid number it reports an error.
<preach>
If request_number is a number then it should be stored in a number column. If it isn't, don't try an convert it to a number.
</preach> -
ORA-01722: invalid number for getting PR information
This is a query ran on Oracle Purchasing database, I want to select all those purchase requisitions which have accounting segment3 value between 100000 and 199999. The query errors out.
As in the below query, even though I said "to_number(ccds.segment3) account_seg" in the inner select query but when I give a where condition "account_seg between 150000 and 160000" in the outer query, the sql errors out with "ORA-01722: invalid number" error.
By commenting out statement "where account_seg between 150000 and 160000", I checked the values returned for segment 3 are all digits and no alphabets.
Whats can be the issue ?
ERROR at line 16:
ORA-01722: invalid number
select requisition_header_id from
select
prls.requisition_header_id requisition_header_id
,to_number(ccds.segment3) account_seg
from
PO_REQUISITION_headers_all prhs
,PO_REQUISITION_LINES_all prls
,PO_REQ_DISTRIBUTIONS_ALL prds
,gl_code_combinations_kfv ccds
where
prhs.requisition_header_id=prls.requisition_header_id
and prls.requisition_line_id=prds.requisition_line_id
and prds.code_combination_id=ccds.code_combination_id
where account_seg between 150000 and 160000Hi this error comes because of data problem.
Some value in segment3 is having alphanumeric data. Check it i am sure about this, i verified!
Adding more info:
Some of the alphanumeric data that i found in my database are:
X00050
F5000
Let us replicate your error:
1. This will run fine:
SELECT segment3
FROM gl_code_combinations_kfv
WHERE segment3 = 'F5000';
SEGMENT3
F5000
But when we say TO_NUMBER of this value, see what happens:
SELECT TO_NUMBER(segment3)
FROM gl_code_combinations_kfv
WHERE segment3 = 'F5000';
SELECT TO_NUMBER(segment3) FROM gl_code_combinations_kfv WHERE segment3 = 'F5000'
ERROR at line 1:
ORA-01722: invalid number
Error proved!
Thanks,
Jithendra
Error Proof added
Jithendra -
Best way to solve ORA-01722: invalid number
Hi,
I recently had to debug a large Merge statement that was getting 'ORA-01722: invalid number' and I found the only way to do it was comment out the columns until I found the culprit :-(
Surely in this day and age there is a better way to do this? Oracle knows which column fails so it there a way of finding it more quickly?
We are using Oracle 9.2
Thanks for any top tips
Regards
Garyyou can do a cursor and trap the exception
create table t1 as select '1' col1, '2' col2 from dual union all select '1','x' from dual union all select 'x','2' from dual union all select 'x','x' from dual;
declare
cursor c1 is select rowid,col1,col2 from t1;
dummy number;
begin
for r1 in c1 loop
begin
select to_number(r1.col1) into dummy from dual;
exception
when INVALID_NUMBER then
dbms_output.put_line(r1.rowid||' col1='||r1.col1);
end;
begin
select to_number(r1.col2) into dummy from dual;
exception
when INVALID_NUMBER then
dbms_output.put_line(r1.rowid||' col2='||r1.col2);
end;
end loop;
end;
AAAKGCAAEAAAAECAAB col2=x
AAAKGCAAEAAAAECAAC col1=x
AAAKGCAAEAAAAECAAD col1=x
AAAKGCAAEAAAAECAAD col2=xHTH
Laurent Schneider
OCM DBA -
EXECUTE IMMEDIATE ORA-01722 invalid number
hi all
i have a plsql procedure in which the following statement which gives this error ORA-01722: invalid number
sql_stmt :='UPDATE Student set '||stu_gradefor||'=TO_NUMBER('||stu_marks||') where UserID='||stu_UID;
EXECUTE IMMEDIATE sql_stmt;
here all variables (stu_marks,stu_gradefor and stu_UID) are varchar2 coming from different procedure(form) but in the table named Student column HW1 (stu_gradefor) is of datatype number.
I have tried a lot but could not make it to work. Is it that we cannot enter an number through EXECUTE IMMEDIATE? If Possible can somebody help me with this?
Thanks a lot.
Regards
Jyoticreate table Student(UserID varchar2(8) not null, HW1 number(3) , HW2 number(3) , PA1 number(3) , ................);
create table Domain(R_Domain varchar2(11) not null, R_Status char(1) not null, R_Date Date null,R_Value varchar2(11) null, R_Mean varchar2(300) not null);
insert into Domain( R_Domain, R_Status, R_Value, R_Mean )values(
'Term','t','PA1','First Programming Assignment');
Full names for HW1, HW2, PA1....are in the Domain table. so in variable stu_gradefor we get the R_Value.
this is true :variable stu_marks is not actually a number, so the TO_NUMBER is causing the error. stu_marks is of datatype varchar2 but the field HW1,.. are all expecting a numeric value.
i tried SELECT TO_NUMBER(stu_marks) INTO gmark FROM DUAL;
sql_stmt :='UPDATE Student set '||stu_gradefor||'=(:1) where UserID='||stu_UID;
EXECUTE IMMEDIATE sql_stmt using gmark;
where gmark is a number but noting works.same error
This can be true:the column userid is a varchar2 column with a mix of numeric and alpha numeric values. userid value that i inserted was'12345678'
i there any other way to handle this situation?
Thanks for replying
Jyoti -
Getting error as ORA-01722: invalid number
Hi below is my query
select count(1) from table1 where table1.rqstid = '83041' AND table1..score_name = 'Small Business Credit Risk Score' AND
to_number(table1.total_score) >= '70' and rownum<2
I tried to convert '70' to 70, but still I got ame error.
In table1 total_score is varchar2(30) data type, but for this rqstid the data is 420, so it should convert 420 to number and compare with 70.
But why I am getting this error? Please help.
If I remove to_number conversion fot total score then this error is not coming, but this will not give correct result for me.
Thanks.CREATE TABLE SBE_SCORE (
RQSTID VARCHAR2 (30) NOT NULL,
SCORE_NAME VARCHAR2 (300),
TOTAL_SCORE VARCHAR2 (30),
RISKLEVEL VARCHAR2 (30),
SUBSCRIBER_ID NUMBER (10))
INSERT INTO SBE_SCORE ( RQSTID, SCORE_NAME, TOTAL_SCORE, RISKLEVEL,
SUBSCRIBER_ID ) VALUES (
'83041', 'Small Business Credit Risk Score for Financial Services', '420', NULL, NULL);
My Query was
SELECT
count(1)
FROM
sbe_score
WHERE
sbe_score.rqstid = '83041' AND
sbe_score.score_name = 'Small Business Credit Risk Score for Financial Services' AND
to_number(sbe_score.total_score) >= '70' and
rownum<2
Error:ORA:01722 Invalid Number
Now I have modified as below and I am able to get correct results
SELECT
count(1)
FROM
sbe_score
WHERE
sbe_score.rqstid = '83041' AND
sbe_score.score_name = 'Small Business Credit Risk Score for Financial Services' AND
to_number(translate(lower(sbe_score.total_score),'abcdefghijklmnopqrstuvwxyz@._','0'))>= 70 and
rownum<2
I I omit r in the translate function then I am getting same error Invalid number, So just I want to know whether the data 420 for total_score is taking "r" internally? withou our knowledge? -
Error Message - ORA-01722 Invalid Number
Hello:
I have the following situation. When I create an organization, a record is inserted into the following table, AGREEMENTS, and populates four fields.
I have an update form which selects the organization from the AGREEMENTS table so the user can populate the rest of the table. In addition, on this form, there is a drop-down box which allows the user to select the name of a legal document along with the version of the document in which the user needs to select. This select list is created via an LOV joining three tables. The item name for this select list is :P6_DOCUMENT.
The code for the LOV is:
SELECT S.DOC_NAME||' - '|| O.VERSION_NO AS DOC, O.ORG_DOC_CURR_KEY
FROM SUPPORTING_DOCS S,
ORG_DOC_CURR_VER O,
AGREEMENTS H
WHERE
S.DOC_TYPE = 'HISA'
AND S.SUPPORTING_DOC_KEY = O.SUPPORTING_DOC_KEY
AND H.ORG_KEY_LE = O.ORG_KEY
AND O.ORG_KEY=:P6_ORG_KEY_LEWhen the user completes the form, the SUBMIT process is a PL/SQL block consisting of an UPDATE statement to update the AGREEMENTS table based on the selected organization and an INSERT statement to insert a record into the AGREEMENTS_DOC table to store the value stored in :P7_DOCUMENT.
Ok, now here is where my problem starts.
When I first bring up the form and I select the organization I want to update, I click the Search button to find the organization and I receive the following error message: ORA-01722 Invalid Number.
At this point all I'm doing is a basic search. There is no insert/update or anything going on. I'm not understanding why I would be receiving this error message.
The search is based on the database column ORG_KEY_LE whose datatype is NUMBER.
In my application, the item assigned to ORG_KEY_LE is P6_ORG_KEY_LE.
I have a PL/SQL block process created (On Load-Before Header) in the Page Rendering area of my page definition. The PL/SQL code that is written is:
BEGIN
IF :P6_SEARCH_ORG != '0' THEN
:P6_ORG_KEY_LE := :P6_SEARCH_ORG;
END IF;
END;I then have an Item created, :P6_SEARCH_ORG, which is a Select List. In the LOV portion of the page for this item, I have the following:
select ORG_KEY_LE display_value, ORG_KEY_LE return_value
from AGREEMENTS
order by 1The reason for using this table is because this table contains the newly created organization which needs to be updated with the remaining columns of data.
I then have a Search button in the Button area which has the following settings:
Button Position: Region Template Position #CHANGE#.
Condition Type: Value of Item in Express 1 is NULL.
Expression 1: :P6_ORG_KEY_LE.
To troubleshoot this problem, I created two pages, one page to do the UPDATE and the second page to do the INSERT.
The SEARCH functionality in both pages are identical.
When I run my UPDATE page, which only involves updating the missing fields, the process works. I have my search box, I'm able to search for the organization, make my updates, and I'm good.
When I run my INSERT page, which involves inserting the record with the assigned document, I receive the error message after I click the SEARCH button. In order to INSERT the record into this table, I first need to SELECT the organization that was UPDATED in the AGREEMENTS table (using the UPDATE page described in above paragraph). When I select the organization, the user can then assign the appropriate legal document to the organization and insert the record into the AGREEMENTS_DOC table.
Can someone help me with this error message? I'm not sure why I am able to perform my SEARCH on a page with the UPDATE statement, not able to perform the SEARCH on the page with my INSERT statement, and not be able to perform the SEARCH on the page that combines the UPDATE and INSERT statements.
I did some more troubleshooting and I do believe my SUBMIT process which contains the INSERT statement is the issue. I created a fourth page which doesn't have a SUBMIT process. I brought up the form, searched for my organization and the information for that organization appeared. The problem is definately with my UPDATE/INSERT process.
The PL/SQL block for the Submit process is the following:
BEGIN
update
MDD.HISA_AGREEMENTS
set
LAST_UPDATED_BY=V('APP_USER'),
APPROVER_SALUTATION=:P6_APPROVER_SALUTATION,
APPROVER_FIRST_NAME=:P6_APPROVER_FIRST_NAME,
APPROVER_MIDDLE_INITIAL=:P6_APPROVER_MIDDLE_INITIAL,
APPROVER_LAST_NAME=:P6_APPROVER_LAST_NAME,
APPROVER_NAME_SUFFIX=:P6_APPROVER_NAME_SUFFIX,
APPROVER_EMAIL_ADDR=:P6_APPROVER_EMAIL_ADDR,
SPONSOR_EMAIL_ADDR=:P6_SPONSOR_EMAIL_ADDR,
APPROVER_TITLE=:P6_APPROVER_TITLE
where
ORG_KEY_LE=:P6_ORG_KEY_LE
INSERT INTO
HISA_AGREEMENT_DOCS
(HISA_AGREEMENT_DOC_KEY,
ORG_KEY_LE,
APPLICATION_KEY,
STATUS,
STATUS_DATE,
CREATED_BY,
ORG_DOC_CURR_KEY)
VALUES
(HISA_AGREEMENT_DOC_KEY_SEQ.NEXTVAL,
:P6_ORG_KEY_LE,
:P6_APPLICATION_KEY,
'C',
SYSDATE,
V('APP_USER'),
:P6_DOCUMENT)
END;There is something wrong with the above statement and I do not understand what it could be. Can someone help?
Thanks for the help.Hi,
I believe you are on to something.
The select list for item :P6_DOCUMENT appears when I first bring up the form. When I select my organization and receive the error message, I clicked on the Session in the Developer's bar. The value in item/field :P6_DOCUMENT shows %null%.
This is the path in which my user would like to accomplish her task:
1. Select an organization
2. Display the information for that organization from the AGREEMENTS table
3. Enter the data for the remaining fields in the AGREEMENTS table
4. Select the document (:P6_DOCUMENT) from the drop-down.
5. Click Submit
6. Update the AGREEMENTS table with data entered in #3.
7. Insert a record into the AGREEMENTS_DOC table with the selection from #4.
Somehow I need the :P6_DOCUMENT field not to show the %null% during the SEARCH functionality. I think that is causing the problem.
How do I fix this? -
How to determine offending column in ORA-01722: invalid number error ...
When an error like
ORA-01722: invalid number error
occurs and you are dealing with many columns that could be the 'culprit', does anyone have a method by which
you can quickly determine offending column?SQL PLus will tell you:
SQL> create table t
2 (col1 number
3 ,col2 number
4 ,col3 number
5 ,col4 number
6 ,col5 number
7 );
Table created.
SQL> create table x
2 (col1 varchar2(10)
3 ,col2 varchar2(10)
4 ,col3 varchar2(10)
5 ,col4 varchar2(10)
6 ,col5 varchar2(10)
7 );
Table created.
SQL> insert into x values ('1','2','x','4','5');
1 row created.
SQL> insert into t(col1,col2,col3,col4,col5)
2 select col1,col2,col3,col4,col5 from x;
select col1,col2,col3,col4,col5 from x
ERROR at line 2:
ORA-01722: invalid numberAnd if you rearrange your sql like this, sql plus will give you the line number of the offending column:
SQL> insert into t
2 (col1
3 ,col2
4 ,col3
5 ,col4
6 ,col5
7 )
8 select col1
9 ,col2
10 ,col3
11 ,col4
12 ,col5
13 from x;
,col3
ERROR at line 10:
ORA-01722: invalid number
Maybe you are looking for
-
Both KB2956128 and KB2956203 causing issue. Removing the patch fixes the issue. I need to know what the best way to remove the patch remotely is. Maybe a SCCM job with this: msiexec /I {90140000-0012-0000-0000-0000000FF1CE}MSIPATCHREMOVE={DEFF916D-42
-
How do I Read a .js File from Mime Repository
How can i read a .js file from Mime Repository, Mime Respository is for Re-Usability Since i need to call a function from a .js file again and again, i keep my .js file in Mime Repository so that i can call the function anywhere by calling the .js Fi
-
This is probably a dumb question but I'd like to author a DVD with video files that can play in a standard DVD player but also include a folder of data (photos) that can be drug onto a computer desktop. Is this possible? iMac G4 (flat panel) Mac OS
-
Dear experts Is it possible to set valuation by company for IS Retail? Is there new version of IS Retail to support the company valuation level? Please advise. Hengki
-
11g R2 database showing ORA 00600 error
Hi experts, Please help,as my database is showing ORA00600 error. For instance, while database shutdown am getting following error ORA-01109 database not open and while starting up *ORA-00600: internal error code, arguments: [kcrfr_resize2][636029440