SlideShare ist ein Scribd-Unternehmen logo
1 von 14
1 Using ORACLE® Using functions (single row and aggregate functions) And the ‘GROUP BY ‘ clause
2 FUNCTIONS We have many functions in Oracle that can be used to perform a myriad of tasks. There are two types of functions viz: Functions take input ,process it and provide the output. Single row functions operate only on one row (1 input and 1 output) Aggregate functions can operate on a range of rows   ( multiple inputs and one output)
3 FUNCTIONS Single row functions can be divided into different parts as: Character Single row functions Number General Conversion Date
4 CHARACTER FUNCTIONS Case manipulation functions Character manipulation functions
5 CHARACTER FUNCTIONS SELECTprod_ID, INITCAP  (prod_name) , CONCAT ('Rs ',prod_cost) AS COST  FROM  product_master WHERE prod_name LIKE(  LOWER  ('TEAK%')); SELECTprod_ID, UPPER   (prod_name) , CONCAT  ('Rs ',prod_cost) AS COST  FROM  product_master WHERE prod_name LIKE (  CONCAT  ( '%',  SUBSTR  ( 'teak_sofa', 6, 4  ))); Equivalent to LIKE ( ‘%sofa’);
6 NUMBER FUNCTIONS SELECT ROUND   (3.14126,4), TRUNC   (3.14126,4) , MOD    ( 22, 7 )  FROM DUAL     ; (DUAL is a dummy table in Oracle used to perform calculations.) SELECTprod_ID , prod_name , ROUND(  MOD       (prod_stock,prod_order),0)                            AS REORDER_LVL FROM product_master ORDER BY REORDER_LVL; (Here we use the alias name to order the output)
7 DATE FUNCTIONS We can use either MONTH or YEAR as parameters in the ROUND and TRUNC functions.
8 DATE MANIPULATIONS Apart from the date functions we can also perform arithmetic operations on dates as:. Adding or subtracting a number to or from a date to get a resultant date. Subtracting two dates to find the number of days between those dates. Adding hours to a date by dividing the number of hours by 24. SELECT   SYSDATEASTODAY, 			(SYSDATE+1) AS NEXT_DAY, 			(SYSDATE-1) AS PREV_DAY FROM DUAL;
9 CONVERSION FUNCTIONS Here in the TO_NUMBER function we are converting the string ‘2000’ to a number 2000. In TO_DATE we have to specify the format of the output date and  In TO_CHAR we have to specify the format of input date to be converted to a string
10 GENERAL FUNCTIONS SELECT prod_ID, prod_name, NVL       (prod_order,0),  NVL2   (prod_sales,'YES','NO'),  NULLIF  	(prod_stock,(prod_order+prod_sales))  AS NULLIF FROM product_master;
11 AGGREGATE FUNCTIONS Aggregate functions take multiple rows as input and give one output. The SYNTAX is: SELECT  column1,column2…….aggregate_function( column)… FROMtable_name WHERE (expression/condition);
12 AGGREGATE FUNCTIONS SELECT   COUNT  (prod_ID) AS COUNT,  MIN  (prod_cost) AS MINIMUM,   MAX  (prod_sales) AS MAXIMUM,   AVG   (prod_cost) AS AVERAGE,   SUM  (prod_stock) AS SUM, ROUND( STDDEV   (prod_sales),3) AS STD_DEVIAYION, ROUND(  VARIANCE   (prod_stock),3) AS VARIANCE FROM product_master; (We can also use ‘*’ in COUNT and ‘DISTINCT’ in AVG )
13 GROUP BY CLAUSE When we wish to divide the table into multiple groups based on some criterion we use the ‘GROUP BY’ clause. It is mandatory that while using a group by clause we include the column used in the group must not be used in a aggregate function in the SELECT statement. SYNTAX: SELECT  column1,column2…….aggregate_function( column)… FROMtable_name GROUP BY column WHERE (expression/condition); It is mandatory to use the group by clause when displaying  any column along with a aggregratefunction.We can also use multiple columns in the group by clause. Use the WHERE clause to furthur filter results.
THANK YOU 14 THANK YOU FOR VIEWING THIS PRESENTATION FOR MORE PRESENTATIONS AND VIDEOS ON ORACLE AND DATAMINING , please visit:   www.dataminingtools.net

Weitere ähnliche Inhalte

Was ist angesagt?

MySQL developing Store Procedure
MySQL developing Store ProcedureMySQL developing Store Procedure
MySQL developing Store Procedure
Marco Tusa
 

Was ist angesagt? (20)

Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)
 
Packages in PL/SQL
Packages in PL/SQLPackages in PL/SQL
Packages in PL/SQL
 
PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts
 
SQL Complete Tutorial. All Topics Covered
SQL Complete Tutorial. All Topics CoveredSQL Complete Tutorial. All Topics Covered
SQL Complete Tutorial. All Topics Covered
 
Sql server windowing functions
Sql server windowing functionsSql server windowing functions
Sql server windowing functions
 
Sql queries presentation
Sql queries presentationSql queries presentation
Sql queries presentation
 
Sql commands
Sql commandsSql commands
Sql commands
 
Plsql
PlsqlPlsql
Plsql
 
MySQL developing Store Procedure
MySQL developing Store ProcedureMySQL developing Store Procedure
MySQL developing Store Procedure
 
SQL Queries Information
SQL Queries InformationSQL Queries Information
SQL Queries Information
 
Basic sql Commands
Basic sql CommandsBasic sql Commands
Basic sql Commands
 
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with ExamplesDML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
 
Best sql plsql material
Best sql plsql materialBest sql plsql material
Best sql plsql material
 
Exception handling in plsql
Exception handling in plsqlException handling in plsql
Exception handling in plsql
 
Sql views
Sql viewsSql views
Sql views
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
 
SQL Tutorial - Basic Commands
SQL Tutorial - Basic CommandsSQL Tutorial - Basic Commands
SQL Tutorial - Basic Commands
 
SQL
SQLSQL
SQL
 
View & index in SQL
View & index in SQLView & index in SQL
View & index in SQL
 
Sql Basics | Edureka
Sql Basics | EdurekaSql Basics | Edureka
Sql Basics | Edureka
 

Ähnlich wie Oracle: Functions

Oracle tips and tricks
Oracle tips and tricksOracle tips and tricks
Oracle tips and tricks
Yanli Liu
 
Understand when to use user defined functions in sql server tech-republic
Understand when to use user defined functions in sql server   tech-republicUnderstand when to use user defined functions in sql server   tech-republic
Understand when to use user defined functions in sql server tech-republic
Kaing Menglieng
 
Analytic & Windowing functions in oracle
Analytic & Windowing functions in oracleAnalytic & Windowing functions in oracle
Analytic & Windowing functions in oracle
Logan Palanisamy
 
New Features of SQL Server 2016
New Features of SQL Server 2016New Features of SQL Server 2016
New Features of SQL Server 2016
Mir Mahmood
 

Ähnlich wie Oracle: Functions (20)

Single row functions
Single row functionsSingle row functions
Single row functions
 
Oracle tips and tricks
Oracle tips and tricksOracle tips and tricks
Oracle tips and tricks
 
Les17
Les17Les17
Les17
 
Understand when to use user defined functions in sql server tech-republic
Understand when to use user defined functions in sql server   tech-republicUnderstand when to use user defined functions in sql server   tech-republic
Understand when to use user defined functions in sql server tech-republic
 
Web Developer make the most out of your Database !
Web Developer make the most out of your Database !Web Developer make the most out of your Database !
Web Developer make the most out of your Database !
 
Oracle_Analytical_function.pdf
Oracle_Analytical_function.pdfOracle_Analytical_function.pdf
Oracle_Analytical_function.pdf
 
Les04
Les04Les04
Les04
 
The Ring programming language version 1.9 book - Part 93 of 210
The Ring programming language version 1.9 book - Part 93 of 210The Ring programming language version 1.9 book - Part 93 of 210
The Ring programming language version 1.9 book - Part 93 of 210
 
Cubing and Metrics in SQL, oh my!
Cubing and Metrics in SQL, oh my!Cubing and Metrics in SQL, oh my!
Cubing and Metrics in SQL, oh my!
 
Analytic & Windowing functions in oracle
Analytic & Windowing functions in oracleAnalytic & Windowing functions in oracle
Analytic & Windowing functions in oracle
 
The Ring programming language version 1.8 book - Part 90 of 202
The Ring programming language version 1.8 book - Part 90 of 202The Ring programming language version 1.8 book - Part 90 of 202
The Ring programming language version 1.8 book - Part 90 of 202
 
Oracle Database Advanced Querying
Oracle Database Advanced QueryingOracle Database Advanced Querying
Oracle Database Advanced Querying
 
Les03
Les03Les03
Les03
 
New Features of SQL Server 2016
New Features of SQL Server 2016New Features of SQL Server 2016
New Features of SQL Server 2016
 
SQL Tunning
SQL TunningSQL Tunning
SQL Tunning
 
Simplifying SQL with CTE's and windowing functions
Simplifying SQL with CTE's and windowing functionsSimplifying SQL with CTE's and windowing functions
Simplifying SQL with CTE's and windowing functions
 
The Ring programming language version 1.10 book - Part 97 of 212
The Ring programming language version 1.10 book - Part 97 of 212The Ring programming language version 1.10 book - Part 97 of 212
The Ring programming language version 1.10 book - Part 97 of 212
 
Les03
Les03Les03
Les03
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
Les03 (Using Single Row Functions To Customize Output)
Les03 (Using Single Row Functions To Customize Output)Les03 (Using Single Row Functions To Customize Output)
Les03 (Using Single Row Functions To Customize Output)
 

Mehr von oracle content (13)

Oracle: Procedures
Oracle: ProceduresOracle: Procedures
Oracle: Procedures
 
Oracle: PLSQL Introduction
Oracle: PLSQL IntroductionOracle: PLSQL Introduction
Oracle: PLSQL Introduction
 
Oracle : DML
Oracle : DMLOracle : DML
Oracle : DML
 
Oracle: Programs
Oracle: ProgramsOracle: Programs
Oracle: Programs
 
Oracle: Commands
Oracle: CommandsOracle: Commands
Oracle: Commands
 
Oracle: Joins
Oracle: JoinsOracle: Joins
Oracle: Joins
 
Oracle:Cursors
Oracle:CursorsOracle:Cursors
Oracle:Cursors
 
Oracle: Control Structures
Oracle:  Control StructuresOracle:  Control Structures
Oracle: Control Structures
 
Oracle: Dw Design
Oracle: Dw DesignOracle: Dw Design
Oracle: Dw Design
 
Oracle: Basic SQL
Oracle: Basic SQLOracle: Basic SQL
Oracle: Basic SQL
 
Oracle Warehouse
Oracle WarehouseOracle Warehouse
Oracle Warehouse
 
Oracle: New Plsql
Oracle: New PlsqlOracle: New Plsql
Oracle: New Plsql
 
Oracle: Fundamental Of Dw
Oracle: Fundamental Of DwOracle: Fundamental Of Dw
Oracle: Fundamental Of Dw
 

Kürzlich hochgeladen

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Kürzlich hochgeladen (20)

Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 

Oracle: Functions

  • 1. 1 Using ORACLE® Using functions (single row and aggregate functions) And the ‘GROUP BY ‘ clause
  • 2. 2 FUNCTIONS We have many functions in Oracle that can be used to perform a myriad of tasks. There are two types of functions viz: Functions take input ,process it and provide the output. Single row functions operate only on one row (1 input and 1 output) Aggregate functions can operate on a range of rows ( multiple inputs and one output)
  • 3. 3 FUNCTIONS Single row functions can be divided into different parts as: Character Single row functions Number General Conversion Date
  • 4. 4 CHARACTER FUNCTIONS Case manipulation functions Character manipulation functions
  • 5. 5 CHARACTER FUNCTIONS SELECTprod_ID, INITCAP (prod_name) , CONCAT ('Rs ',prod_cost) AS COST FROM product_master WHERE prod_name LIKE( LOWER ('TEAK%')); SELECTprod_ID, UPPER (prod_name) , CONCAT ('Rs ',prod_cost) AS COST FROM product_master WHERE prod_name LIKE ( CONCAT ( '%', SUBSTR ( 'teak_sofa', 6, 4 ))); Equivalent to LIKE ( ‘%sofa’);
  • 6. 6 NUMBER FUNCTIONS SELECT ROUND (3.14126,4), TRUNC (3.14126,4) , MOD ( 22, 7 ) FROM DUAL ; (DUAL is a dummy table in Oracle used to perform calculations.) SELECTprod_ID , prod_name , ROUND( MOD (prod_stock,prod_order),0) AS REORDER_LVL FROM product_master ORDER BY REORDER_LVL; (Here we use the alias name to order the output)
  • 7. 7 DATE FUNCTIONS We can use either MONTH or YEAR as parameters in the ROUND and TRUNC functions.
  • 8. 8 DATE MANIPULATIONS Apart from the date functions we can also perform arithmetic operations on dates as:. Adding or subtracting a number to or from a date to get a resultant date. Subtracting two dates to find the number of days between those dates. Adding hours to a date by dividing the number of hours by 24. SELECT SYSDATEASTODAY, (SYSDATE+1) AS NEXT_DAY, (SYSDATE-1) AS PREV_DAY FROM DUAL;
  • 9. 9 CONVERSION FUNCTIONS Here in the TO_NUMBER function we are converting the string ‘2000’ to a number 2000. In TO_DATE we have to specify the format of the output date and In TO_CHAR we have to specify the format of input date to be converted to a string
  • 10. 10 GENERAL FUNCTIONS SELECT prod_ID, prod_name, NVL (prod_order,0), NVL2 (prod_sales,'YES','NO'), NULLIF (prod_stock,(prod_order+prod_sales)) AS NULLIF FROM product_master;
  • 11. 11 AGGREGATE FUNCTIONS Aggregate functions take multiple rows as input and give one output. The SYNTAX is: SELECT column1,column2…….aggregate_function( column)… FROMtable_name WHERE (expression/condition);
  • 12. 12 AGGREGATE FUNCTIONS SELECT COUNT (prod_ID) AS COUNT, MIN (prod_cost) AS MINIMUM, MAX (prod_sales) AS MAXIMUM, AVG (prod_cost) AS AVERAGE, SUM (prod_stock) AS SUM, ROUND( STDDEV (prod_sales),3) AS STD_DEVIAYION, ROUND( VARIANCE (prod_stock),3) AS VARIANCE FROM product_master; (We can also use ‘*’ in COUNT and ‘DISTINCT’ in AVG )
  • 13. 13 GROUP BY CLAUSE When we wish to divide the table into multiple groups based on some criterion we use the ‘GROUP BY’ clause. It is mandatory that while using a group by clause we include the column used in the group must not be used in a aggregate function in the SELECT statement. SYNTAX: SELECT column1,column2…….aggregate_function( column)… FROMtable_name GROUP BY column WHERE (expression/condition); It is mandatory to use the group by clause when displaying any column along with a aggregratefunction.We can also use multiple columns in the group by clause. Use the WHERE clause to furthur filter results.
  • 14. THANK YOU 14 THANK YOU FOR VIEWING THIS PRESENTATION FOR MORE PRESENTATIONS AND VIDEOS ON ORACLE AND DATAMINING , please visit: www.dataminingtools.net