Monday, February 14, 2011

Some tips about select COALESCE function in oracle

COALESCE  will return the first not null value. 
It requires at least two arguments
If the arguments entered are of different datatype then it will throw an error

SQL> select  coalesce(1,3,null,'jeet') from dual;
select  coalesce(1,3,null,'jeet') from dual
                          *
ERROR at line 1:
ORA-00932: inconsistent datatypes: expected NUMBER got CHAR
SQL> select  coalesce('a','as',null) from dual;
C
-
a
SQL> select COALESCE(null,null) from dual;
C
-

SQL> select COALESCE (null) from dual;
select COALESCE (null) from dual
       *
ERROR at line 1:
ORA-00938: not enough arguments for function
SQL> select COALESCE('a') from dual;
select COALESCE('a') from dual
       *
ERROR at line 1:
ORA-00938: not enough arguments for function

No comments: