Welcome to plsql4all.blogspot.com SQL, MYSQL, ORACLE, TERADATA, MONGODB, MARIADB, GREENPLUM, DB2, POSTGRESQL.

Saturday, 6 September 2014

COALESCE function in MariaDB

COALESCE function in MariaDB return default value if there is NULL value in the second expression.

Syntax:-

COALESCE (DEFAULT_VALUE,'EXPRESSION,'')

Example:-

SELECT * fROM EMPLOYEE;

     EMPNO EMPNAME                  SALARY     DEPTNO
---------- -------------------- ---------- ----------
         1 CHANCHAL                   1000         10
         2 WANKHADE                   2000         20
         3 SCOTT                      3000        200
         4 TIGER                      4000        200
         5 JOHN                       5000        300
         6 JAKE                       6000        300
         7 null      null       null


SELECT COALESCE(EMPNAME,'CHANCHAL') AS EMPNAME FROM EMPLOYEE WHERE EMPNO=7;

--> CHANCHAL

SELECT COALESCE(NULL,'CHANCHAL') AS EMPNAME FROM EMPLOYEE WHERE EMPNO=7;

--> CHANCHAL

SELECT COALESCE(EMPNO,100) FROM EMPLOYEE WHERE EMPNO=7;

--> 7




Read Also:-  IFNULL function in MySql

No comments:

Post a Comment

Please provide your feedback in the comments section above. Please don't forget to follow.