Oracle PL/SQL Tutorial/Numerical Math Functions/POWER
Содержание
POWER(2, 1)
<source lang="sql">
SQL> select POWER(2, 1) from dual; POWER(2,1)
2</source>
POWER(2, 3)
<source lang="sql">
SQL> select POWER(2, 3) from dual; POWER(2,3)
8</source>
POWER(x, y) gets the result of x raised to the power y.
The following example uses POWER() to display 2 raised to the power 1 and 3, respectively:
<source lang="sql">
SQL> SELECT POWER(2, 1), POWER(2, 3) FROM dual; POWER(2,1) POWER(2,3)
----------
2 8
SQL></source>
select power(2,3), power(-2,3)
<source lang="sql">
SQL> SQL> SQL> SQL> select power(2,3), power(-2,3)
2 from dual;
POWER(2,3) POWER(-2,3)
-----------
8 -8
SQL></source>
Using the POWER function
The POWER function requires two arguments.
The first argument is the value that you would like raised to some exponential power.
The second argument is the power (exponent) that you would like the number raised to.
<source lang="sql">
SQL> SQL> SQL> -- create demo table SQL> create table myTable(
2 id NUMBER(2), 3 value NUMBER(6,2) 4 ) 5 /
Table created. SQL> SQL> -- prepare data SQL> insert into myTable(ID, value)values (1,9)
2 /
1 row created. SQL> insert into myTable(ID, value)values (2,2.11)
2 /
1 row created. SQL> insert into myTable(ID, value)values (3,3.44)
2 /
1 row created. SQL> insert into myTable(ID, value)values (4,-4.21)
2 /
1 row created. SQL> insert into myTable(ID, value)values (5,10)
2 /
1 row created. SQL> insert into myTable(ID, value)values (6,3)
2 /
1 row created. SQL> insert into myTable(ID, value)values (7,-5.88)
2 /
1 row created. SQL> insert into myTable(ID, value)values (8,123.45)
2 /
1 row created. SQL> insert into myTable(ID, value)values (9,98.23)
2 /
1 row created. SQL> SQL> select * from myTable
2 / ID VALUE
----------
1 9 2 2.11 3 3.44 4 -4.21 5 10 6 3 7 -5.88 8 123.45 9 98.23
9 rows selected. SQL> SQL> select power(value, 2) from myTable
2 /
POWER(VALUE,2)
81 4.4521 11.8336 17.7241 100 9 34.5744 15239.9025 9649.1329
9 rows selected. SQL> SQL> select power(value, 3) from myTable
2 /
POWER(VALUE,3)
729 9.393931 40.707584 -74.618461 1000 27 -203.29747 1881365.96 947834.325
9 rows selected. SQL> SQL> SQL> -- clean the table SQL> drop table myTable
2 /
Table dropped. SQL></source>