Thursday, February 27, 2014

SUM OF TWO COLUMNS (COLUMN1+COLUMN2) & SUM(COLUMN NAME) FUNCTION OPERATION WITH NULL VALUES, WHAT WOULD BE IT'S OUTPUT?

> SELECT COL1, COL2, COL3, COL4, COL1+COL2, COL2+COL3, COL3+COL4, COL1+COL4 FROM TEMP_TABLE
> SELECT SUM(COL1), SUM(COL2), SUM(COL3), SUM(COL4) FROM TEMP_TABLE



CREATE TABLE TEMP_TABLE 
(
  COL1 VARCHAR2(10), 
  COL2 VARCHAR2(10), 
  COL3 VARCHAR2(10), 
  COL4 VARCHAR2(10)
);

INSERT INTO TEMP_TABLE VALUES ('10','20','30','40');
INSERT INTO TEMP_TABLE VALUES ('10','','30','40');
INSERT INTO TEMP_TABLE VALUES ('10','','','40');
INSERT INTO TEMP_TABLE VALUES ('','','','');











SUM OF COLUMNS: SUM WITH NULL ALWAYS RETURN A NULL VALUE
SELECT COL1, COL2, COL3, COL4, COL1+COL2, COL2+COL3, COL3+COL4, COL1+COL4 FROM TEMP_TABLE 










SUM FUNCTION WITH INDIVIDUAL COLUMN NAME: WILL RETURN THE SUM OF THE COLUMN EITHER THE COLUMN CONTAINS NULL
SELECT SUM(COL1), SUM(COL2), SUM(COL3), SUM(COL4) FROM TEMP_TABLE











NOTE: IF YOU HAVE DOUBTS, KINDLY CONTACT ME VIA THIS BLOG

No comments:

Post a Comment