The below sql code gives me ora - Invalid Number error. How do i solve this ? I guess its related to group by function.
SELECT SUM(RAT_CCY_SELL)/COUNT(dat_last_upd)
FROM RD_FCY_RATE_HIST
WHERE cod_ccy ='EUR'
AND to_char( pk_ba_global.dat_process,'mm') - to_char(DAT_LAST_UPD,'mm')='1';
I think you should be using the average function AVG
here:
SELECT
AVG(RAT_CCY_SELL)
FROM
RD_FCY_RATE_HIST
WHERE
cod_ccy = 'EUR' AND
TO_CHAR(SYSDATE, 'yyyy-mm') = TO_CHAR(DAT_LAST_UPD, 'yyyy-mm')
I assumed here that the column DAT_LAST_UPD
contains the date for each record with regard to determining what data corresponds to the current month. If not, then replace that column.
I think the error is because of subtraction of two strings.
Some info from this link are following
Cause
You executed a SQL statement that tried to convert a string to a number,
but it was unsuccessful.
Resolution
The option(s) to resolve this Oracle error are:
Option #1
----------
Only numeric fields or character fields that contain
numeric values can be used in arithmetic operations.
Make sure that all expressions evaluate to numbers.
Option #2
-----------
If you are adding or subtracting from dates,
make sure that you added/substracted a numeric value from the date.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.