send a mail if count (*) >0 in oracle

The question is vague. I’m assuming that you are using oracle 10g and above.If you are trying to send mail through PL/SQL, you can use UTL_MAIL package. You can try something like

CREATE OR REPLACE PROCEDURE p_test_mail
AS
var_count NUMBER;
CURSOR c1
IS
SELECT COUNT(*)
FROM nb005 nb
JOIN emp_reset_id e
ON nb.qteref = qrc.emp_quote_ref
WHERE nb.pcsstg=51;
BEGIN
OPEN c1;
LOOP
FETCH c1 INTO var_count;
EXIT
WHEN c1%NOTFOUND;
IF var_count > 0 THEN
utl_mail.send(sender => '[email protected]', recipients => '[email protected]', subject => 'Your Subject', MESSAGE => 'Your Message');
END IF;
END LOOP;
CLOSE c1;
END;

There are some prerequisites to use UTL_MAIL package. You can find those details here

Leave a Comment