Question: I'd like to know how can I get a message if my SUM salary is 0. Please check my code:

```
DECLARE    
   v_sum_sal   NUMBER(10,2); 
   v_deptno    NUMBER NOT NULL := 10;           
BEGIN
  SELECT    SUM(salary)  -- group function
  INTO v_sum_sal  FROM  employees
  WHERE     department_id = v_deptno;

   IF  v_sum_sal = 0 THEN 
 DBMS_OUTPUT.PUT_LINE ('You have selected 0 employees ');
else
  DBMS_OUTPUT.PUT_LINE ('The sum of salary is ' || v_sum_sal);
  end if;
END;

```

Answer: 
If there are no matches, then the `sum()` returns `NULL`, not 0. Here are two approaches.

Change the query to:

```
  SELECT COALESCE(SUM(salary), 0)  -- group function
  INTO v_sum_sal  FROM  employees
  WHERE department_id = v_deptno;

```

Alternatively, change the `if` to:

```
  IF  v_sum_sal IS NULL THEN 

```
Here what is happening in your code, if your table doesnt contain the dept id you provided. It will give a NULL output. So if you put a exception handling condition it will work like a charm.

```
DECLARE
  v_sum_sal NUMBER(10,2);
  v_deptno  NUMBER NOT NULL := 10;
BEGIN
  BEGIN
    SELECT SUM(salary) -- group function
    INTO v_sum_sal
    FROM employees
    WHERE department_id = v_deptno;
  EXCEPTION
  WHEN NO_DATA_FOUND THEN
    v_sum_sal:=0;
  END;
  IF v_sum_sal = 0 THEN
    DBMS_OUTPUT.PUT_LINE ('You have selected 0 employees ');
  ELSE
    DBMS_OUTPUT.PUT_LINE ('The SUM OF salary
IS  
' || v_sum_sal);
  END IF;
END; 

```