Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

 
 Home
 E-mail Us
 Oracle Articles
New Oracle Articles


 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog


 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Analysis
 Design
 Implementation
 Oracle Support


 SQL Tuning
 Security

 Oracle UNIX
 Oracle Linux
 Monitoring
 Remote s
upport
 Remote plans
 Remote
services
 Application Server

 Applications
 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S
upport  
 Development  

 Implementation


 Consulting Staff
 Consulting Prices
 Help Wanted!

 


 Oracle Posters
 Oracle Books

 Oracle Scripts
 Ion
 Excel-DB  

Don Burleson Blog 


 

 

 


 

 

   
 

Oracle SQL Multi-row functions

Multi Row SQL Functions

They operate on a set of rows and returns one result or one result per group.  We will cover groups in Chapter 3.  This is a powerful feature because it allows you to generate subtotals, sums and averages within the SQL that is retrieving the data.  For now, we will apply the functions to all the rows we return.  In the next chapter, we will break up our returning rows into groups and apply the functions to each of the groups independently.

count

The count function counts the number of rows it processes and returns that number.  You can use the distinct clause to count only distinct rows.

SELECT
  COUNT(*),
  COUNT(1),
  COUNT(store_key),
  COUNT(DISTINCT store_key)
FROM
  sales;
  COUNT(*)   COUNT(1) COUNT(STORE_KEY) COUNT(DISTINCTSTORE_KEY)
---------- ---------- ---------------- ------------------------
       100        100              100                       10

First, we count the number of rows using count(*).  In the second example, we do the same thing.  Some DBAs believe that count(1) is more efficient than count(*), but this is a myth.  In example three, we count the number of store_keys.  If a row is processed with a NULL store_key, it will be counted in example one and two but not in three or four.  In example four, we count distinct store_keys.  So there are 100 rows in the sales table, each row has a store_key (no NULL store_keys) and there are ten distinct store_keys in the table (listed below).

SQL> SELECT DISTINCT store_key FROM sales;
STOR
----
S101
S102
S103
S104
S105
S106
S107
S108
S109
S110
sum(c1)
The function sum adds the value of the column c1 for all the rows processed and returns the total.  NULLs are skipped.  Sum can also use the distinct format.
SELECT
  SUM(quantity)
FROM
  sales; 
SUM(QUANTITY)
-------------
       110550 
SELECT
  SUM(quantity)
FROM
  sales
WHERE
 
Get the Complete
Oracle SQL Tuning Information 

The landmark book "Advanced Oracle SQL Tuning  The Definitive Reference"  is filled with valuable information on Oracle SQL Tuning. This book includes scripts and tools to hypercharge Oracle 11g performance and you can buy it for 30% off directly from the publisher.
��  
 
 
Oracle Training at Sea
 
 
 
 
oracle dba poster
 

 
Follow us on Twitter 
 
Oracle performance tuning software 
 
Oracle Linux poster
 
 
 

 

Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  

and include the URL for the page.


                    









Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


 

Copyright © 1996 -  2020

All rights reserved by Burleson

Oracle ® is the registered trademark of Oracle Corporation.