Press "Enter" to skip to content

How to Check If Number is Negative in Oracle?

In Oracle, use SIGN function to check if the number is negative, zero or positive. Below is an example to how to check if the number is negative in Oracle.

Syntax

SIGN (n)

SIGN Function Example

SET SERVEROUTPUT ON;
DECLARE
n NUMBER := -5;
BEGIN
IF SIGN (n) < 0
THEN
DBMS_OUTPUT.put_line ('Number is negative.');
ELSIF SIGN (n) = 0
THEN
DBMS_OUTPUT.put_line ('Number is zero.');
ELSE
DBMS_OUTPUT.put_line ('Number is positive.');
END IF;
END;
/

Output

Number is negative.
PL/SQL procedure successfully completed.

See also:

Vinish Kapoor

I am a full stack developer and writing about development. I document everything I learn and help thousands of people. foxinfotech.in is created, written, and maintained by me, it is built on WordPress, and hosted by Bluehost. Connect with me on Facebook, Twitter, GitHub and get notifications for new posts.

You may also like:

Be First to Comment

    Leave a Reply

    Your email address will not be published. Required fields are marked *