I don't understand why implicit conversion isn't working for me for the median function in Oracle. (Obviously I have plenty of ways to work around it with proper explicit conversions, but I'm wondering why it's happening at all. Am I missing something obvious or is this a bug? It just seems so unlikely to be a bug.)
I have a table with a varchar2(255 byte) column. It's nullable, but contains no nulls. All of the strings in this field are numeric.
I can do this:
select avg(this_field) from this_table
and that's fine.
I can do this:
select median(to_number(this_field)) from this_table
and that's fine too.
But I can't do this:
select median(this_field) from this_table
because I get the error "ORA-30495: The argument should be of numeric or date/datetime type."
The Oracle documentation on MEDIAN says that implicit conversion is done:
This function takes as arguments any numeric data type or any nonnumeric data type that can be implicitly converted to a numeric data type.
This is the exact same wording as the Oracle documentation on AVG.
And yet:
select median(to_char('1')) from dual;
ORA-30495: The argument should be of numeric or date/datetime type.
select avg(to_char('1')) from dual;
1
select median(to_number(to_char('1'))) from dual;
1
So...what's going on?