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

FoxInfotech.in is created, written, and maintained by Vinish Kapoor. It is built on WordPress, and hosted by Bluehost. Connect with Vinish on Facebook, Twitter, and GitHub.

You may also like: