Three Function

Quick Understanding Of Oracle Number Functions
NUMBER FUNCTIONS IN ORACLE
- Particularly in business everything is guided by numbers
- • Fortunately Oracle, provides functions which deal with numbers.
- • Oracle functions deal with three classes of numbers:
Single values, group values AND list values.
ü Single value, is one number, such as 24.45.
ü Group values, is all numbers in a column of a table.
ü List values, is a series of numbers in columns of a row.
Lets best understand by an example consider the climate table below.
CityName MinTemp MaxTemp DatedOn
------------------------------------------------------------------
Mumbai 33.33 40.5 12-mar-2010
Chennai 32.33 42.50 12-mar-2010
Calcutta 34.45 38.0 12-mar-2010
Delhi 36.89 46.89 12-mar-2010
Mumbai 33.45 45.89 13-mar-2010
Single value, is one value in a column.
Group values, is values in a column, of all rows.for example all values of MinTemp column.
List Values, is collection of values in columns of a particular row. For example 33.33 and 40.5 are from the first row of the above table.
- Functions acting on single values.
Function Description
-------------------------------------------------------------------------------------------------
Value1 + value2 Here + function, adds value1 with value2.
Value1 – value2 Here – function, Substracts value2 from value1.
Value1 * value2 Here * function, multiplies value2 with value1.
Value1 / value2 Here / function, Divides value1 with value2.
ABS(value) Returns ABSolute value, ie returns positive value.
SIGN(value) Returns,
1 if value positive,
-1 if value negative,
0 if value zero.
CEIL(value) Returns Integer, just above the given value or equal to the value.
FLOOR(value) Returns Integer, just below the given or equal to the value.
MOD(value,divisor) Returns, reminder of value/divisor.
NVL(value,substitute) Substitutes value, if value is null.
POWER(value,exponent) Returns, Value raised to an exponent.
SQRT(value) Returns, Square root of value
TRUNC(value, precision) Returns, Value truncated to precision.
ROUND(value,precision) Returns, value Rounded to precision.
Before we see some examples, lets' understand what does dual mean. Dual is a dummy table in oracle database, which is used for testing sql statements.
Let us work some examples, making use of functions acting on single values. Here letters in blue are results given by oracle when respective query is executed
SQL>select 6 + 2 from dual;
6 + 2
--------
8
SQL>select 6 - 2 from dual;
6 - 2
------
4
SQL>select 6 * 2 from dual;
6 * 2
-------
12
SQL>select 6 / 2 from dual;
6/2
----
3
SQL>select ABS(-121) from dual;
ABS(-121)
--------------
121
SQL>select ABS(121) from dual;
ABS(121)
-------------
121
SQL> select ABS(-121) from dual;
ABS(-121)
----------------
121
SQL> select sign(121) from dual;
SIGN(121)
----------------
1
SQL> select sign(-121) from dual;
SIGN(-121)
-----------------
-1
SQL> select sign(0) from dual;
SIGN(0)
-----------------
0
SQL> select CEIL(121.22) from dual;
CEIL(121.22)
--------------------
122
SQL> select CEIL(-121.22) from dual;
CEIL(-121.22)
---------------------
-121
SQL> select CEIL(121) from dual;
CEIL(121)
-----------------
121
SQL> select CEIL(-121) from dual;
CEIL(-121)
-----------------
-121
SQL> select FLOOR(121.22) from dual;
FLOOR(121.22)
-----------------------
121
SQL> select FLOOR(-121.22) from dual;
FLOOR(-121.22)
------------------------
-122
SQL> select FLOOR(121) from dual;
FLOOR(121)
------------------
121
SQL> select FLOOR(-121) from dual;
FLOOR(-121)
-------------------
-121
SQL> select MOD(10,3) from dual;
MOD(10,3)
----------------
1
SQL> select MOD(10,2) from dual;
MOD(10,2)
-----------------
0
SQL> select MOD(10,0) from dual;
MOD(10,0)
-----------------
10
SQL> select MOD(0,10) from dual;
MOD(0,10)
----------------
0
SQL> select MOD(0,0) from dual;
MOD(0,0)
---------------
0
Consider the climate table below
CityName MinTemp MaxTemp DatedOn
-------------------------------------------------------------------------------
Secunderabad 27 33 12-feb-2008
Hyderabad 24 35 23-nov-2008
Ahmedabad 34 26-mar-2008
Gaziabad 23 34 24-sep-2008
On observing the above table, we find that in 3rd row, value in, column MaxTemp is unavailable. Now by making use of NVL function we can substitute the unavailable data with some value.
Select CityName, NVL(MaxTemp,33.5) from dual;
CityName MaxTemp
----- ----------------------------------
Secunderabad 33
Hyderabad 35
Ahmedabad 33.5
Gaziabad 34
Remember
ü NVL function does not update the data base. It temporarily substitutes and displays on the screen.
SQL> select POWER (2, 3) from dual;
POWER (2,3)
-------------------
8
SQL> select SQRT(4) from dual;
SQRT(4)
-----------------
2
SQL> select ROUND(34.4556,2) from dual;
ROUND(34.4556,2)
----------------------------
34.46
SQL> select ROUND(34.4556,3) from dual;
ROUND(34.4556,3)
----------------------------
34.456
SQL> select ROUND(-34.4556,2) from dual;
ROUND(-34.4556,2)
----------------------------
-34.46
SQL> select TRUNC(34.4556,2) from dual;
TRUNC(34.4556,2)
---------------------------
34.45
SQL> select TRUNC(34.4556,3) from dual;
TRUNC(34.4556,3)
---------------------------
34.455
- Functions acting on Group of values.
These Functions act, on values, of a column, in all rows, of a table.
The most commonly used functions are
Function Description
-------------------------------------------------------------------------------------------------
AVG(ColumnName) Average of all values in the column.
COUNT(ColumnName) number - of rows or of values in column.
SUM(ColumnName) sum total, of all values in the column.
MIN(ColumnName) Returns least of all values in that column.
MAX(ColumnName) Returns highest of all values in that column.
STDDEV(Columnname) Usual statistical meaning.
VARIANCE(ColumnName) Usual statistical meaning,
Lets' consider the emp table, from the scott/tiger schema of oracle database
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17-DEC-80 800 20 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10 10
7788 SCOTT ANALYST 7566 19-APR-87 3000 20 20
7839 KING PRESIDENT 17-NOV-81 5000 10 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30 20
7876 ADAMS CLERK 7788 23-MAY-87 1100 20 20
7900 JAMES CLERK 7698 03-DEC-81 950 30 30
7902 FORD ANALYST 7566 03-DEC-81 3000 20 20
7934 MILLER CLERK 7782 23-JAN-82 1300 10 10
Lets work some examples, the letters in blue are the results returned by the oracle database,in reply to a query
Find the maximum salary paid
SQL> select MAX(sal) from emp;
MAX(SAL)
--------------
5000
Find the minimum salary paid
SQL> select MIN(sal) from emp;
MIN(SAL)
---------------
800
Find the average salary paid
SQL> select AVG(sal) from emp;
AVG(SAL)
-----------------
2073.21429
Find the total amount paid as salaries to the employees
SQL> select SUM(sal) from emp;
SUM(SAL)
-----------------
29025
COUNT functions usage is situational:
- Is used to count the number of rows in a table, if the argument is *(asterisk)
SQL> select COUNT(*) from emp;
COUNT(*)
------------------
14
- Is used to count number of available data in a column of a table.
Find the number of, NOT NULL values, in the column mgr of emp table?
SQL> select COUNT(mgr) from emp;
COUNT(MGR)
--------------------
13
- DISTINCT key word, can be used, with every GROUP Function, but its usage is more felt, with COUNT function. Let us see apply DISTINCT to find, how many types of jobs are there in emp table
SQL> select COUNT(DISTINCT JOB) from emp;
COUNT(DISTINCTJOB)
----------------------------------
5
There are 5 types of JOB are in emp table.
Lets write a query to find number, of NULL values in mgr column of emp table
SQL> select COUNT(*)-COUNT(mgr) from emp;
COUNT(*)-COUNT(MGR)
-----------------------------------
1
There is one NULL, in mgr column, of emp table.
Remember
ü Asterisk can not be used with any other GROUP function, other than COUNT.
ü DISTINCT finds its usage mostly with COUNT function.
ü COUNT can be used either with character column or number column, where as other GROUP functions can be used only with numerical data.
ü By now you should have observed, COUNT does not perform any arithmetic operations with the values of a column but it either counts number of values in a column or number rows in a table.
ü The alternative to DISTINCT is ALL, which is the default.
- Functions acting on list of values
These functions act on values, in two or more columns, of a row, in a table
The most frequently used functions are described in table below
FUNCTION DESCRIPTION
-----------------------------------------------------------------------------------------------------------------------------
LEAST(value1,value2,value3,..) Returns least value,among the values in the argument list.
GREATEST(value1,value2,value3,..) Returns greatest value, among the values in the argument
List
Consider the StudentMarks table below, with columns as student name, marks in physics, maths,
Chemistry
StudentName MathMarks PhysicsMarks ChemistryMarks
------------------------------------------------------------------------------------------------------
Lova Raju 67 76 89
Siri 100 99 99
Viji 99 90 88
Koti 98 88 87
Now write a query that would display student name and highest mark obtained, among the three subjects
Sql>select StudentName,Greatest(MathMarks,PhysicsMarks,ChemistryMarks) as HighestMark from StudentMarks;
ENAME HIGHESTMARK
-------------------------------------
Lova Raju 89
Siri 100
Viji 99
Koti 98
Write a query that would display student name and the least mark obtained, among the three subjects
Sql> select StudentName, LEAST(MathMarks,PhysicsMarks,ChemistryMarks) as LowestMark from StudentMarks;
-
NULLs in -List Value Functions and Single Value Functions:
- List value functions treat NULL values same as that of single value functions.
- Single value functions produce NULL result, if any value is NULL.
- List value functions produce NULL result, if any value in the list is NULL
-
NULLS in - GROUP Value Functions :
- Group value functions treat NULL values differently than single value functions.
- Group value functions ignore NULL values and go ahead with the result.
Remember
ü Group value functions, ignore NULL values
ü Single value and List value functions, don't ignore NULL values.
About the Author
The author is a trainer in oracle and Java
u can get in toch with me on raju.allu@yahoo.com
Highline Excel Class 09: SUMIF Function Formula 3 Examples
![]() |
![]() NEW Moen Enliven Three Function Standard Showerhead in Chrome 21313 $8.99 Time Remaining: 8d 3h 19m Buy It Now for only: $8.99 Buy It Now |
![]() Elegant Black Three Dial Army Multi Function Mechanical Mens AUTO Watch Steel $1.39 Time Remaining: 16h 38m |
![]() Moen Enliven Three Function Standard Showerhead in Chrome 21313 $8.99 Time Remaining: 14d 23h 26m Buy It Now for only: $8.99 Buy It Now |
![]() TRAILER LIGHT KIT WIRING TESTER THREE LIGHT FUNCTIONS TAIL RT AND LT SIGNALS $2.00 Time Remaining: 24d 15h 38m Buy It Now for only: $2.00 Buy It Now |
![]() Broan P66V Three function control switch $21.99 Time Remaining: 18h 44m Buy It Now for only: $21.99 Buy It Now |
![]() Moen 3 Replenish Chrome Three Function Showerhead $20.00 Time Remaining: 28d 5h 1m Buy It Now for only: $20.00 Buy It Now |
![]() MonteVerde MV40058 Invincia Executive 3 Three Multi Function Ink Pen 40058 $49.99 Time Remaining: 10d 17h 59m Buy It Now for only: $49.99 Buy It Now |
![]() The Medical Interview The Three Function Approach by Julian Bird and Steven $9.99 Time Remaining: 5h 36m Buy It Now for only: $14.50 Buy It Now |
![]() Moen Vestige Vertical Spa Three Function Shower Faucet Trim Set Brushed Nickel $265.33 Time Remaining: 29d 9h 29m Buy It Now for only: $265.33 Buy It Now |
![]() BROAN NUTONE 685VL Three Function Controls Ivory Finish 2 Gang $19.79 Time Remaining: 15d 21h 47m Buy It Now for only: $19.79 Buy It Now |
![]() New In Box MOEN Chrome threefunction 3 diameter standard showerhead free ship $17.99 Time Remaining: 14d 21h 11m Buy It Now for only: $17.99 Buy It Now |
![]() NEW Paper Mate PhD Three Function Multi Pen 69072 $8.99 Time Remaining: 25d 3h 43m Buy It Now for only: $8.99 Buy It Now |
![]() Broan NuTone 66V Three Function Controls Ivory Finish $19.99 Time Remaining: 23d 21h 28m Buy It Now for only: $19.99 Buy It Now |
![]() Three in One 3 in 1 Tripod Flashlight by Totes LED Multi Function $3.99 Time Remaining: 5d 3h 55m Buy It Now for only: $9.99 Buy It Now |
![]() MOEN Moentrol 3320 THREE FUNCTION TRANSFER SHOWER VALVE 1 2 IPS NEW $149.99 Time Remaining: 27d 6h 59m Buy It Now for only: $149.99 Buy It Now |
![]() Danze 3 Three Function Traditional Showerhead D460006 $24.95 Time Remaining: 9d 2h 26m Buy It Now for only: $24.95 Buy It Now |
![]() Newest BGA Chip repair station Holder Jig with magnifier Three functions in one $27.54 Time Remaining: 12d 11h 12m Buy It Now for only: $27.54 Buy It Now |
![]() THREE DIMENSIONAL MULTI FUNCTION PILLOW $80.00 Time Remaining: 28d 31m Buy It Now for only: $80.00 Buy It Now |
![]() Fashion Silver Rhinestone Three Tier Ankle Chain Or Bracelet Multi Function $3.95 Time Remaining: 11d 22h 44m Buy It Now for only: $3.95 Buy It Now |
![]() DELTA 56513 THREE FUNCTION COMTEMPORARY SHOWER WALL MOUNT 25 GALLONS PER MINUTE $47.00 Time Remaining: 27d 20h 18m Buy It Now for only: $47.00 Buy It Now |
![]() BROAN MODEL 66V THREE FUNCTION ROCKER SWITCH CONTROL IVORY $9.99 Time Remaining: 4d 7h 1m Buy It Now for only: $14.99 Buy It Now |
![]() Lot of 2 Three Function Bartender Tools $1.20 Time Remaining: 4d 19h 5m Buy It Now for only: $1.20 Buy It Now |
![]() Three in one Card Mahjong Poker Game with Function 2284 $12.99 Time Remaining: 23d 12h 1m Buy It Now for only: $12.99 Buy It Now |
![]() Broan NuTone THREE FUNCTION WALL CONTROL fan lights P66WN white 120V 15A heaters $21.63 Time Remaining: 4d 4h 44m Buy It Now for only: $21.63 Buy It Now |
![]() PRICE PFISTER THREE FUNCTION HANDHELD SHOWERHEAD CHROME $39.99 Time Remaining: 10d 1h 39m Buy It Now for only: $39.99 Buy It Now |
![]() S Aquabrass 12699 Three Function Slide Bar Handshower $93.90 Time Remaining: 3d 10h 26m Buy It Now for only: $93.90 Buy It Now |
![]() BROAN NUTONE P66W THREE FUNCTION CONTROL 1499 NR $14.99 Time Remaining: 6d 6h 16m |
![]() The Medical Interview The Three Function Approach 2e Steven A Cole Julian B $4.91 Time Remaining: 4d 23h 45m Buy It Now for only: $4.91 Buy It Now |
![]() Moen Enliven Collection three setting functions massage spray chrome shower head $12.00 Time Remaining: 23d 2h 43m Buy It Now for only: $12.00 Buy It Now |
![]() Delta Traditional 54713 PB Polished Brass Three Function Hand Shower $79.99 Time Remaining: 3d 2h 7m Buy It Now for only: $79.99 Buy It Now |
![]() Hansgrohe 04072620 Oil Rubbed Bronze Chroma C Three Function Hand Shower Only w $72.15 Time Remaining: 12d 23h 17m Buy It Now for only: $72.15 Buy It Now |
![]() Kohler K 10591 CP Polished Chrome Classic Bancroft MasterClean Three Function $62.49 Time Remaining: 9d 3h 45m Buy It Now for only: $62.49 Buy It Now |
![]() Led Light 3 IN 1 ALL PURPOSE THREE FUNCTION LIGHT $7.00 Time Remaining: 4d 3h 34m Buy It Now for only: $10.00 Buy It Now |
![]() Broan 66V Three Function Control Ivory Plastic Wall Plate 15A 120V 60Hz NEW $19.99 Time Remaining: 28d 21h 38m Buy It Now for only: $19.99 Buy It Now |
![]() KENT FAITH 52MM THREE FUNCTION LENS HOOD RUBBER $5.99 Time Remaining: 12h 49m Buy It Now for only: $5.99 Buy It Now |
![]() Rohl 1311APC Polished Chrome Three Function Hand Shower $535.50 Time Remaining: 22d 12h 43m Buy It Now for only: $535.50 Buy It Now |
![]() ULTRASONIC PIEZO SCALER COMPATIBLE EMS TIPS E3 new brand with three function $183.00 Time Remaining: 5d 22h 40m Buy It Now for only: $183.00 Buy It Now |
![]() Danze D460007AC 450 Series Six Inch Three Function Showerhead Antique Copper $34.95 Time Remaining: 12d 4h 51m Buy It Now for only: $34.95 Buy It Now |
![]() Danze D465002PNV AC0ED011157 Polished Nickel Three Function Personal Shower Kit $86.88 Time Remaining: 22d 13h 29m Buy It Now for only: $86.88 Buy It Now |
![]() Moen Inspire 21333 Three Function Standard Showerhead $35.00 Time Remaining: 23h 30m Buy It Now for only: $50.00 Buy It Now |
![]() Paper Mate PhD Three Function Multi Pen or Paper Mate PhD Multi 3 In 1 Pen2 Mod $10.89 Time Remaining: 10d 23h 17m Buy It Now for only: $10.89 Buy It Now |
![]() Danze D460008AC 460 Series Six Inch Three Function Showerhead Antique Copper $34.95 Time Remaining: 11d 19h 31m Buy It Now for only: $34.95 Buy It Now |
![]() Three in one Card Mahjong Poker Game with Function 2265 $8.99 Time Remaining: 23d 12h 1m Buy It Now for only: $8.99 Buy It Now |
![]() 49MM Three function lens hood Rubber for Sony A900 A850 A700 A550 A450 A400 A390 $7.99 Time Remaining: 22d 23h 55m Buy It Now for only: $7.99 Buy It Now |
![]() Leather three zip Multi function Wallet key case cell phone Bag handbag Wristlet $26.83 Time Remaining: 24d 8h 37m Buy It Now for only: $26.83 Buy It Now |
![]() Danze 3 Danze 400 Three Function Shower Head in Antique Copper D460006AC $20.00 Time Remaining: 6d 21h 11m Buy It Now for only: $25.99 Buy It Now |
![]() Kitchen Supplies Rotating Peeler Three Functions Pink $0.98 Time Remaining: 4d 23h 37m Buy It Now for only: $0.98 Buy It Now |
![]() Delta Three Function Handshower 54513 PB Polished Brass $209.00 Time Remaining: 27d 11h 23m Buy It Now for only: $209.00 Buy It Now |
![]() Danze D465002RB AC0ED011157 Oil Rubbed Bronze Three Function Personal Shower Kit $93.75 Time Remaining: 12d 23h 18m Buy It Now for only: $93.75 Buy It Now |
![]() Newest BGA Chip repair station Holder Jig with magnifier Three functions in one $28.99 Time Remaining: 6d 11h 41m Buy It Now for only: $28.99 Buy It Now |
![]() Moen 3233EP Envi Three Function 4 Diameter Eco Performance Showerhead Chrome $56.24 Time Remaining: 27d 22h 15m Buy It Now for only: $56.24 Buy It Now |
![]() Weller WR3000M 120v/400w Digital Self-Contained 3-Function Rework Station with Tools Sale Price: $1,999.99 Eligible for free shipping!Availability: Usually ships in 24 hours See Reviews For This Product DescriptionMicroprocessor automatically recognizes and controls the temperature of each of three tools at the same time. The digital temperature can be set to any temperature within the range. Hot air range is 150-1022°F (65-550°C), and for soldering/desoldering, 150-850°F (65-454°C)... |
![]() Heavy-Duty 3-Function 1" Impact Hammer Drill, SDS-Plus Bits, Chisels Sale Price: $56.99 Eligible for free shipping!Availability: Usually ships in 1-2 business days See Reviews For This Product |
![]() Vestil LC-803 Steel and Plastic Multi-Function Luggage Cart/Chair, 3" x 3/4" Wheel, 65 lbs and 225 lbs Capacity, Folded 26-1/2" Length x 13" Width x 17" Height Sale Price: $35.14 Eligible for free shipping!Availability: Usually ships in 24 hours See Reviews For This Product DescriptionThe Multi-Function Luggage Cart/Chair is constructed of both steel and plastic. Cart will handle lightweight uniform loads up to 65 pounds. The chair position holds up to 225 uniform pounds. This Cart/Chair is perfect for use at trade shows for transporting products, literature and small parts... |
![]() The Medical Interview: The Three-Function Approach List Price: Sale Price: $40.86 You save: $4.09 (9%) Eligible for free shipping!Availability: Usually ships in 24 hours See Reviews For This Product DescriptionThe 2nd Edition of THE MEDICAL INTERVIEW presents basic interviewing skills in a systematic approach designed to assist students in mastering communicating with patients. A new unit on managing common challenging communicating situations* including language and cultural barriers, pediatric and elderly patients, and non-verbal communication*has been added... |
![]() Weller WR3M 120v/400w Digital Self-Contained 3-Function Rework Station Sale Price: $1,399.99 Eligible for free shipping!Availability: Usually ships in 24 hours See Reviews For This Product DescriptionDigital Self-Contained 3 Function Rework Station |
![]() Vestil MPO-3 Multi Function Package Opener Sale Price: $14.16 Eligible for free shipping!Availability: Usually ships in 24 hours See Reviews For This Product DescriptionMulti-function package opener quickly cuts strapping, film, rope, tape. The heavy-duty retractable claw removes staples. |
![]() Weller WP80 80 Watts/24V Soldering Pencil For WR3M Digital Self-Contained 3 Function Rework Station Sale Price: $95.68 Eligible for free shipping!Availability: Usually ships in 24 hours See Reviews For This Product |
![]() Weller HAP200 200Watts/24V Hot Air Pencil For WR3M Digital Self-Contained 3 Function Rework Station Sale Price: $236.98 Eligible for free shipping!Availability: Usually ships in 24 hours See Reviews For This Product Description- Controlled hot air for non-contact soldering and desoldering of SMDs - For use with WR3M rework station only - Must plug into first channel of WR3M - Ideal for use with lead free solders - Finger switch controls the adjustable pump on the WR3M - Comes with adapter for small hot air nozzles - Use with optional WRK Weller Repair Kit - Use only Weller replacement tips or your warranty will be voided |
![]() Kimble Kimax, Volumetric Pipet With the "To Contain" and "To Deliver" Functions, 3mL (Case of 6) Sale Price: $79.76 Eligible for free shipping!Availability: Usually ships in 24 hours See Reviews For This Product DescriptionKimax Class A volumetric pipet with the "to contain" and "to deliver" functions. Capacity: 3mL. Color Band: Black. Kimble #: 37007-3. |
![]() Barbara K! BK07916 3-Piece Multi Function Screwdriver Setá List Price: Sale Price: $11.47 You save: $1.52 (12%) Eligible for free shipping!Availability: Usually ships in 24 hours See Reviews For This Product |






















































Eligible for free shipping!


















