Skip to Main Content

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question.

Asked: August 15, 2006 - 12:52 pm UTC

Last updated: August 15, 2006 - 3:47 pm UTC

Version: 9

Viewed 10K+ times! This question is

You Asked

Tom

What is the difference between "select null from dual" and "select to_number(null) from dual"

Is it only a semantic meaning or does SQL allocate a variable of number datatype for the to_number one?

and Tom said...

one selects NULL and will be of type "string"

the other selects NULL and will be of type "number"


ops$tkyte%ORA10GR2> create or replace view vw as select null x, to_number(null) y from dual;

View created.

ops$tkyte%ORA10GR2> desc vw
Name Null? Type
---------------------------------------- -------- ----------------------------
X VARCHAR2
Y NUMBER


Rating

  (2 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Alexander the ok, August 15, 2006 - 3:30 pm UTC

Tom then why can you:

SQL> create table t ( x number);

Table created.

SQL> insert into t values(to_char(null));

1 row created.

SQL> create table z (x varchar(1));

Table created.

SQL> insert into z values (to_number(null));

1 row created.

? 

Tom Kyte
August 15, 2006 - 3:47 pm UTC

for the same reason you can:

insert into t values ( '1' );
insert into z values ( 1 );

implicit conversions.

A reader, August 15, 2006 - 4:04 pm UTC

THanks

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library