Sign function

Sign returns:

  • 1 If The Argument Is Positive;
  • -1 If The Argument Is Negative;
  • 0 If The Argument Is Negative.

SQL> select sign(10) from dual;

  SIGN(10)
----------
         1

SQL>
SQL> select sign(-10) from dual;

 SIGN(-10)
----------
        -1

SQL>
SQL> select sign(0) from dual;

   SIGN(0)
----------
         0

SQL>

create table TestTable(
      ID                 VARCHAR2(4 BYTE)         NOT NULL,
      MyNumber           Number(8,2)
    );

insert into TestTable (ID, MyNumber)values('1',12);
insert into TestTable (ID, MyNumber)values('1',-1);
insert into TestTable (ID, MyNumber)values('1',1.1);

SQL> select myNumber from testTable;

  MYNUMBER
----------
        12
        -1
       1.1

SQL> select sign(myNumber) from testTable;

SIGN(MYNUMBER)
--------------
             1
            -1
             1

SQL>
Home »
Oracle »
Numeric Functions » 

Related: