SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Tendances

3963066 pl-sql-notes-only
3963066 pl-sql-notes-only3963066 pl-sql-notes-only
3963066 pl-sql-notes-only
Ashwin Kumar
 

Tendances (20)

Controlling User Access -Data base
Controlling User Access -Data baseControlling User Access -Data base
Controlling User Access -Data base
 
SQL commands
SQL commandsSQL commands
SQL commands
 
Oraclesql
OraclesqlOraclesql
Oraclesql
 
Packages in PL/SQL
Packages in PL/SQLPackages in PL/SQL
Packages in PL/SQL
 
Arrays C#
Arrays C#Arrays C#
Arrays C#
 
Stored procedure
Stored procedureStored procedure
Stored procedure
 
SQL - DML and DDL Commands
SQL - DML and DDL CommandsSQL - DML and DDL Commands
SQL - DML and DDL Commands
 
Sql Functions And Procedures
Sql Functions And ProceduresSql Functions And Procedures
Sql Functions And Procedures
 
Sql commands
Sql commandsSql commands
Sql commands
 
PLSQL Cursors
PLSQL CursorsPLSQL Cursors
PLSQL Cursors
 
Oracle report from ppt
Oracle report from pptOracle report from ppt
Oracle report from ppt
 
Database Objects
Database ObjectsDatabase Objects
Database Objects
 
Including Constraints -Oracle Data base
Including Constraints -Oracle Data base Including Constraints -Oracle Data base
Including Constraints -Oracle Data base
 
3963066 pl-sql-notes-only
3963066 pl-sql-notes-only3963066 pl-sql-notes-only
3963066 pl-sql-notes-only
 
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
 
Manipulating Data Oracle Data base
Manipulating Data Oracle Data baseManipulating Data Oracle Data base
Manipulating Data Oracle Data base
 
Introduction to sql
Introduction to sqlIntroduction to sql
Introduction to sql
 
5. stored procedure and functions
5. stored procedure and functions5. stored procedure and functions
5. stored procedure and functions
 
Writing Basic SQL SELECT Statements
Writing Basic SQL SELECT StatementsWriting Basic SQL SELECT Statements
Writing Basic SQL SELECT Statements
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional array
 

Similaire à 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
 

Similaire à 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)
 

Plus de 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
 

Dernier

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Dernier (20)

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 

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