SQRT function

Sqrt returns the square root of a number or value.


SQL> select sqrt(4) from dual;

   SQRT(4)
----------
         2

SQL>

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

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


SQL> select myNumber from testTable;

  MYNUMBER
----------
     12.12
       1.1

SQL> select sqrt(myNumber) from testTable;

SQRT(MYNUMBER)
--------------
    3.48137904
    1.04880885

SQL>

sqrt doesn't accept negative values.


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

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

SQL> select myNumber from testTable;

  MYNUMBER
----------
     12.12
      -1.1

SQL> select sqrt(myNumber) from testTable;
ERROR:
ORA-01428: argument '-1.1' is out of range



no rows selected

SQL> drop table testTable;

Table dropped.

SQL>
SQL>

Functions can be nested. The following example combines the sqrt and abs:


SQL> select myNumber from testTable;

  MYNUMBER
----------
     12.12
      -1.1

SQL> select sqrt(abs(myNumber)) from testTable;

SQRT(ABS(MYNUMBER))
-------------------
         3.48137904
         1.04880885

SQL> drop table testTable;
Home »
Oracle »
Numeric Functions » 

Related: