I have a table in an Oracle 11g database that's similar to the following:
CREATE TABLE BUDGET_DATA (
BUDGET_MONTH varchar2(30)
, BUDGET_CATEGORY varchar2(30)
, BUDGET_AMOUNT varchar2(30)
)
All the values in BUDGET_AMOUNT are numbers. When I do select SUM, the values come out as I would have expected if BUDGET_AMOUNT was actually stored as a numeric.
SELECT BUDGET_MONTH, SUM(BUDGET_AMOUNT)
FROM BUDGET_DATA
GROUP BY BUDGET_MONTH
I'm curious, does Oracle perform a native conversion to number if you put a VARCHAR2 in an aggregate function? I would have expected that I'd have to do the following to get the data to sum correctly:
SELECT BUDGET_MONTH, SUM(TO_NUMBER(BUDGET_AMOUNT))
FROM BUDGET_DATA
GROUP BY BUDGET_MONTH
Can someone point me to some documentation about this behavior? I haven't been able to find anything to describe it.
Best Answer
Implicit Data Conversion
You can find more on the above URL.
After you read it, forget everything written there, and use explicit conversion. Relying on implicit conversion is bad practice.