How to Check If Number is Negative in Oracle?

How to Check If Number is Negative in Oracle?

  • SQL
  • 1 min read

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:

  • Oracle Date function examples