SlideShare a Scribd company logo
1 of 21
Download to read offline
Oracle Database, SQL
Day 2
Trainers:
Gurpreet Singh
Oracle Database, SQL2
Day 2 Agenda
Oracle Database, SQL3
Constraints
Constraints are the rules enforced on the data columns of a table. These are used to limit the type of data that
can go into a table. This ensures the accuracy and reliability of the data in the database.
Constraints can be divided into following two types:
• Column level constraints : limits only column data
• Table level constraints : limits whole table data
1. NOT NULL
2. UNIQUE
3. PRIMARY KEY
4. FOREIGN KEY
5. CHECK
6. DEFAULT
Oracle Database, SQL4
NOT NULL
NOT NULL constraint restricts a column from having a NULL value. Once NOT NULL constraint is applied to a
column, you cannot pass a null value to that column. It enforces a column to contain a proper value. One
important point to note about NOT NULL constraint is that it cannot be defined at table level.
CREATE TABLE Student
(s_id int NOT NULL,
Name varchar(60),
Age int);
Oracle Database, SQL5
NOT NULL
NOT NULL constraint restricts a column from having a NULL value. Once NOT NULL constraint is applied to a
column, you cannot pass a null value to that column. It enforces a column to contain a proper value. One
important point to note about NOT NULL constraint is that it cannot be defined at table level.
Oracle Database, SQL6
UNIQUE
UNIQUE constraint ensures that a field or column will only have unique values. A UNIQUE constraint field will
not have duplicate data. UNIQUE constraint can be applied at column level or table level.
Oracle Database, SQL7
PRIMARY KEY
PRIMARY KEY constraint uniquely identifies each record in a database. A Primary Key must contain unique
value and it must not contain null value. Usually Primary Key is used to index the data inside the table.
Oracle Database, SQL8
FOREIGN KEY
FOREIGN KEY is used to relate two tables. FOREIGN KEY constraint is also used to restrict actions that would
destroy links between tables
Oracle Database, SQL9
FOREIGN KEY
Oracle Database, SQL10
CHECK
CHECK constraint is used to restrict the value of a column between a range. It performs check on the values,
before storing them into the database. Its like condition checking before saving data into a column
Oracle Database, SQL11
Aggregate Functions
Aggregate functions return a single result row based on groups of rows, rather than on single rows. Aggregate
functions can appear in select lists and in ORDER BY and HAVING clauses. They are commonly used with the
GROUP BY clause in a SELECT statement, where Oracle Database divides the rows of a queried table or view into
groups. In a query containing a GROUP BY clause, the elements of the select list can be aggregate functions,
GROUP BY expressions, constants, or expressions involving one of these. Oracle applies the aggregate functions
to each group of rows and returns a single result row for each group.
All the dependent columns or columns used in GROUP BY function must form the basis of grouping, hence must
be included in GROUP BY clause also.
GROUP BY clause does not support the use of column alias, but the actual names.
GROUP BY clause can only be used with aggregate functions like SUM, AVG, COUNT, MAX, and MIN. If it is used
with single row functions,Oracle throws and exception as "ORA-00979: not a GROUP BY expression".
Aggregate functions cannot be used in a GROUP BY clause. Oracle will return the "ORA-00934: group function
not allowed" here error message.
SELECT DEPARTMENT_ID, JOB_ID, SUM (SAL) FROM employees GROUP BY DEPARTMENT_ID, JOB_ID;
Oracle Database, SQL12
Aggregate Functions
Many (but not all) aggregate functions that take a single argument accept these clauses:
• DISTINCT and UNIQUE, which are synonymous, cause an aggregate function to consider only distinct values
of the argument expression. The syntax diagrams for aggregate functions in this chapter use the keyword
DISTINCT for simplicity.
• ALL causes an aggregate function to consider all values, including all duplicates.
Oracle Database, SQL13
Aggregate Functions
SUM( [ALL | DISTINCT] expression )
AVG( [ALL | DISTINCT] expression )
COUNT( [ALL | DISTINCT] expression )
COUNT(*)
MAX(expression)
MIN(expression)
Oracle Database, SQL14
Sum
SUM(ALL/DISTINCT expr)
Returns the sum value of expr.
SELECT
SUM(salary),
SUM(ALL salary),
SUM(DISTINCT salary)
FROM
employees;
Oracle Database, SQL15
Avg
AVG(ALL/DISTINCT expr)
Returns the average value of expr.
SELECT
AVG(salary),
AVG(ALL salary),
AVG(DISTINCT salary)
FROM
employees;
Oracle Database, SQL16
Count
COUNT(*) OR COUNT(ALL/DISTINCT expr)
Returns the number of rows in the query. If you specify expr then count ignore nulls. If you specify the asterisk
(*), this function returns all rows, including duplicates and nulls. COUNT never returns null.
SELECT
COUNT(manager_id),
COUNT(*),
COUNT(ALL manager_id),
COUNT(DISTINCT manager_id)
FROM
employees;
Oracle Database, SQL17
Max
MAX(ALL/DISTINCT expr)
Returns the maximum value of expr.
SELECT
MAX(salary),
MAX(ALL salary),
MAX(DISTINCT salary)
FROM
employees;
Oracle Database, SQL18
Min
MIN(ALL/DISTINCT expr)
Returns the minimum value of expr.
SELECT
MIN(salary),
MIN(ALL salary),
MIN(DISTINCT salary)
FROM
employees;
Oracle Database, SQL19
Aggregate Functions
A WHERE clause is used to filter rows BEFORE the GROUPING action
A HAVING clause filters rows AFTER the GROUPING action
SELECT
department_id,
SUM(salary)
FROM
employees
WHERE
department_id <> 100
GROUP BY
department_id
HAVING
SUM(salary) >= 15000;
CONTACTS
20
Gurpreet Singh
Senior Software Engineer
CUG. 2142
M. +91-9803723925
Gurpreet.singh2@soprasteria.com
Oracle Database, SQL
Oracle Database, SQL21

More Related Content

What's hot (20)

Sq lite
Sq liteSq lite
Sq lite
 
Sql database object
Sql database objectSql database object
Sql database object
 
Introduction to SQL, SQL*Plus
Introduction to SQL, SQL*PlusIntroduction to SQL, SQL*Plus
Introduction to SQL, SQL*Plus
 
Adbms
AdbmsAdbms
Adbms
 
lovely
lovelylovely
lovely
 
advanced sql(database)
advanced sql(database)advanced sql(database)
advanced sql(database)
 
SQL- Introduction to PL/SQL
SQL- Introduction to  PL/SQLSQL- Introduction to  PL/SQL
SQL- Introduction to PL/SQL
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
 
Sql coding-standard-sqlserver
Sql coding-standard-sqlserverSql coding-standard-sqlserver
Sql coding-standard-sqlserver
 
Using T-SQL
Using T-SQL Using T-SQL
Using T-SQL
 
SQL JOINS
SQL JOINSSQL JOINS
SQL JOINS
 
Creating and Managing Tables -Oracle Data base
Creating and Managing Tables -Oracle Data base Creating and Managing Tables -Oracle Data base
Creating and Managing Tables -Oracle Data base
 
Database Systems - SQL - DCL Statements (Chapter 3/4)
Database Systems - SQL - DCL Statements (Chapter 3/4)Database Systems - SQL - DCL Statements (Chapter 3/4)
Database Systems - SQL - DCL Statements (Chapter 3/4)
 
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
 
Intro to T-SQL - 1st session
Intro to T-SQL - 1st sessionIntro to T-SQL - 1st session
Intro to T-SQL - 1st session
 
Getting Started with MySQL II
Getting Started with MySQL IIGetting Started with MySQL II
Getting Started with MySQL II
 
Etl2
Etl2Etl2
Etl2
 
Sql intro & ddl 1
Sql intro & ddl 1Sql intro & ddl 1
Sql intro & ddl 1
 
SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive
 
Chapter8 my sql revision tour
Chapter8 my sql revision tourChapter8 my sql revision tour
Chapter8 my sql revision tour
 

Similar to Oracle SQL Part 2

Sql overview-1232931296681161-1
Sql overview-1232931296681161-1Sql overview-1232931296681161-1
Sql overview-1232931296681161-1sagaroceanic11
 
Application sql issues_and_tuning
Application sql issues_and_tuningApplication sql issues_and_tuning
Application sql issues_and_tuningAnil Pandey
 
Assignment 3
Assignment 3Assignment 3
Assignment 3SneaK3
 
Advanced Sql Training
Advanced Sql TrainingAdvanced Sql Training
Advanced Sql Trainingbixxman
 
PPT of Common Table Expression (CTE), Window Functions, JOINS, SubQuery
PPT  of Common Table Expression (CTE), Window Functions, JOINS, SubQueryPPT  of Common Table Expression (CTE), Window Functions, JOINS, SubQuery
PPT of Common Table Expression (CTE), Window Functions, JOINS, SubQueryAbhishek590097
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptxSherinRappai1
 
Cursors, triggers, procedures
Cursors, triggers, proceduresCursors, triggers, procedures
Cursors, triggers, proceduresVaibhav Kathuria
 
Sql scripting sorcerypaper
Sql scripting sorcerypaperSql scripting sorcerypaper
Sql scripting sorcerypaperoracle documents
 
SQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdfSQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdfDraguClaudiu
 
SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343
SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343
SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343Edgar Alejandro Villegas
 
Database COMPLETE
Database COMPLETEDatabase COMPLETE
Database COMPLETEAbrar ali
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptxSherinRappai
 
SQL dabatase interveiw pdf for interveiw preparation
SQL dabatase  interveiw pdf for interveiw preparationSQL dabatase  interveiw pdf for interveiw preparation
SQL dabatase interveiw pdf for interveiw preparationkumarvikesh2841998
 
3963066 pl-sql-notes-only
3963066 pl-sql-notes-only3963066 pl-sql-notes-only
3963066 pl-sql-notes-onlyAshwin Kumar
 

Similar to Oracle SQL Part 2 (20)

Sql overview-1232931296681161-1
Sql overview-1232931296681161-1Sql overview-1232931296681161-1
Sql overview-1232931296681161-1
 
Application sql issues_and_tuning
Application sql issues_and_tuningApplication sql issues_and_tuning
Application sql issues_and_tuning
 
Assignment 3
Assignment 3Assignment 3
Assignment 3
 
Interview Questions.pdf
Interview Questions.pdfInterview Questions.pdf
Interview Questions.pdf
 
Sql commands
Sql commandsSql commands
Sql commands
 
Advanced Sql Training
Advanced Sql TrainingAdvanced Sql Training
Advanced Sql Training
 
PPT of Common Table Expression (CTE), Window Functions, JOINS, SubQuery
PPT  of Common Table Expression (CTE), Window Functions, JOINS, SubQueryPPT  of Common Table Expression (CTE), Window Functions, JOINS, SubQuery
PPT of Common Table Expression (CTE), Window Functions, JOINS, SubQuery
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
 
Cursors, triggers, procedures
Cursors, triggers, proceduresCursors, triggers, procedures
Cursors, triggers, procedures
 
Sql scripting sorcerypaper
Sql scripting sorcerypaperSql scripting sorcerypaper
Sql scripting sorcerypaper
 
SQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdfSQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdf
 
SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343
SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343
SQL – The Natural Language for Analysis - Oracle - Whitepaper - 2431343
 
Database COMPLETE
Database COMPLETEDatabase COMPLETE
Database COMPLETE
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
 
SQL Query
SQL QuerySQL Query
SQL Query
 
SQL dabatase interveiw pdf for interveiw preparation
SQL dabatase  interveiw pdf for interveiw preparationSQL dabatase  interveiw pdf for interveiw preparation
SQL dabatase interveiw pdf for interveiw preparation
 
SQL Overview
SQL OverviewSQL Overview
SQL Overview
 
MSSQL_Book.pdf
MSSQL_Book.pdfMSSQL_Book.pdf
MSSQL_Book.pdf
 
UNIT2.ppt
UNIT2.pptUNIT2.ppt
UNIT2.ppt
 
3963066 pl-sql-notes-only
3963066 pl-sql-notes-only3963066 pl-sql-notes-only
3963066 pl-sql-notes-only
 

More from Gurpreet singh

Introduction to Oracle Fusion BIP Reporting
Introduction to Oracle Fusion BIP ReportingIntroduction to Oracle Fusion BIP Reporting
Introduction to Oracle Fusion BIP ReportingGurpreet singh
 
Understanding Flex Fields with Accounting Flexfields(Chart of Accounts) in O...
Understanding Flex Fields with  Accounting Flexfields(Chart of Accounts) in O...Understanding Flex Fields with  Accounting Flexfields(Chart of Accounts) in O...
Understanding Flex Fields with Accounting Flexfields(Chart of Accounts) in O...Gurpreet singh
 
Oracle Application Developmenr Framework
Oracle Application Developmenr FrameworkOracle Application Developmenr Framework
Oracle Application Developmenr FrameworkGurpreet singh
 
Generics and collections in Java
Generics and collections in JavaGenerics and collections in Java
Generics and collections in JavaGurpreet singh
 
IO Streams, Serialization, de-serialization, autoboxing
IO Streams, Serialization, de-serialization, autoboxingIO Streams, Serialization, de-serialization, autoboxing
IO Streams, Serialization, de-serialization, autoboxingGurpreet singh
 
Creating business group in oracle apps
Creating business group in oracle appsCreating business group in oracle apps
Creating business group in oracle appsGurpreet singh
 
Defing locations in Oracle Apps
Defing locations in Oracle AppsDefing locations in Oracle Apps
Defing locations in Oracle AppsGurpreet singh
 
Assigning role AME_BUS_ANALYST
Assigning role AME_BUS_ANALYSTAssigning role AME_BUS_ANALYST
Assigning role AME_BUS_ANALYSTGurpreet singh
 
Introduction to Data Flow Diagram (DFD)
Introduction to Data Flow Diagram (DFD)Introduction to Data Flow Diagram (DFD)
Introduction to Data Flow Diagram (DFD)Gurpreet singh
 
Ingenium test(Exam Management System) Project Presentation (Full)
Ingenium test(Exam Management System) Project Presentation (Full)Ingenium test(Exam Management System) Project Presentation (Full)
Ingenium test(Exam Management System) Project Presentation (Full)Gurpreet singh
 
Computer Graphics Notes
Computer Graphics NotesComputer Graphics Notes
Computer Graphics NotesGurpreet singh
 

More from Gurpreet singh (20)

Introduction to Oracle Fusion BIP Reporting
Introduction to Oracle Fusion BIP ReportingIntroduction to Oracle Fusion BIP Reporting
Introduction to Oracle Fusion BIP Reporting
 
Why Messaging system?
Why Messaging system?Why Messaging system?
Why Messaging system?
 
Understanding Flex Fields with Accounting Flexfields(Chart of Accounts) in O...
Understanding Flex Fields with  Accounting Flexfields(Chart of Accounts) in O...Understanding Flex Fields with  Accounting Flexfields(Chart of Accounts) in O...
Understanding Flex Fields with Accounting Flexfields(Chart of Accounts) in O...
 
Oracle Application Developmenr Framework
Oracle Application Developmenr FrameworkOracle Application Developmenr Framework
Oracle Application Developmenr Framework
 
Java Servlet part 3
Java Servlet part 3Java Servlet part 3
Java Servlet part 3
 
Oracle SQL Part1
Oracle SQL Part1Oracle SQL Part1
Oracle SQL Part1
 
Generics and collections in Java
Generics and collections in JavaGenerics and collections in Java
Generics and collections in Java
 
IO Streams, Serialization, de-serialization, autoboxing
IO Streams, Serialization, de-serialization, autoboxingIO Streams, Serialization, de-serialization, autoboxing
IO Streams, Serialization, de-serialization, autoboxing
 
Java Servlets Part 2
Java Servlets Part 2Java Servlets Part 2
Java Servlets Part 2
 
Creating business group in oracle apps
Creating business group in oracle appsCreating business group in oracle apps
Creating business group in oracle apps
 
Defing locations in Oracle Apps
Defing locations in Oracle AppsDefing locations in Oracle Apps
Defing locations in Oracle Apps
 
Assigning role AME_BUS_ANALYST
Assigning role AME_BUS_ANALYSTAssigning role AME_BUS_ANALYST
Assigning role AME_BUS_ANALYST
 
PL/SQL Part 5
PL/SQL Part 5PL/SQL Part 5
PL/SQL Part 5
 
PL/SQL Part 3
PL/SQL Part 3PL/SQL Part 3
PL/SQL Part 3
 
PL/SQL Part 2
PL/SQL Part 2PL/SQL Part 2
PL/SQL Part 2
 
PL/SQL Part 1
PL/SQL Part 1PL/SQL Part 1
PL/SQL Part 1
 
Introduction to Data Flow Diagram (DFD)
Introduction to Data Flow Diagram (DFD)Introduction to Data Flow Diagram (DFD)
Introduction to Data Flow Diagram (DFD)
 
Ingenium test(Exam Management System) Project Presentation (Full)
Ingenium test(Exam Management System) Project Presentation (Full)Ingenium test(Exam Management System) Project Presentation (Full)
Ingenium test(Exam Management System) Project Presentation (Full)
 
Computer Graphics Notes
Computer Graphics NotesComputer Graphics Notes
Computer Graphics Notes
 
Learn Java Part 11
Learn Java Part 11Learn Java Part 11
Learn Java Part 11
 

Recently uploaded

CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 

Recently uploaded (20)

E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 

Oracle SQL Part 2

  • 1. Oracle Database, SQL Day 2 Trainers: Gurpreet Singh
  • 3. Oracle Database, SQL3 Constraints Constraints are the rules enforced on the data columns of a table. These are used to limit the type of data that can go into a table. This ensures the accuracy and reliability of the data in the database. Constraints can be divided into following two types: • Column level constraints : limits only column data • Table level constraints : limits whole table data 1. NOT NULL 2. UNIQUE 3. PRIMARY KEY 4. FOREIGN KEY 5. CHECK 6. DEFAULT
  • 4. Oracle Database, SQL4 NOT NULL NOT NULL constraint restricts a column from having a NULL value. Once NOT NULL constraint is applied to a column, you cannot pass a null value to that column. It enforces a column to contain a proper value. One important point to note about NOT NULL constraint is that it cannot be defined at table level. CREATE TABLE Student (s_id int NOT NULL, Name varchar(60), Age int);
  • 5. Oracle Database, SQL5 NOT NULL NOT NULL constraint restricts a column from having a NULL value. Once NOT NULL constraint is applied to a column, you cannot pass a null value to that column. It enforces a column to contain a proper value. One important point to note about NOT NULL constraint is that it cannot be defined at table level.
  • 6. Oracle Database, SQL6 UNIQUE UNIQUE constraint ensures that a field or column will only have unique values. A UNIQUE constraint field will not have duplicate data. UNIQUE constraint can be applied at column level or table level.
  • 7. Oracle Database, SQL7 PRIMARY KEY PRIMARY KEY constraint uniquely identifies each record in a database. A Primary Key must contain unique value and it must not contain null value. Usually Primary Key is used to index the data inside the table.
  • 8. Oracle Database, SQL8 FOREIGN KEY FOREIGN KEY is used to relate two tables. FOREIGN KEY constraint is also used to restrict actions that would destroy links between tables
  • 10. Oracle Database, SQL10 CHECK CHECK constraint is used to restrict the value of a column between a range. It performs check on the values, before storing them into the database. Its like condition checking before saving data into a column
  • 11. Oracle Database, SQL11 Aggregate Functions Aggregate functions return a single result row based on groups of rows, rather than on single rows. Aggregate functions can appear in select lists and in ORDER BY and HAVING clauses. They are commonly used with the GROUP BY clause in a SELECT statement, where Oracle Database divides the rows of a queried table or view into groups. In a query containing a GROUP BY clause, the elements of the select list can be aggregate functions, GROUP BY expressions, constants, or expressions involving one of these. Oracle applies the aggregate functions to each group of rows and returns a single result row for each group. All the dependent columns or columns used in GROUP BY function must form the basis of grouping, hence must be included in GROUP BY clause also. GROUP BY clause does not support the use of column alias, but the actual names. GROUP BY clause can only be used with aggregate functions like SUM, AVG, COUNT, MAX, and MIN. If it is used with single row functions,Oracle throws and exception as "ORA-00979: not a GROUP BY expression". Aggregate functions cannot be used in a GROUP BY clause. Oracle will return the "ORA-00934: group function not allowed" here error message. SELECT DEPARTMENT_ID, JOB_ID, SUM (SAL) FROM employees GROUP BY DEPARTMENT_ID, JOB_ID;
  • 12. Oracle Database, SQL12 Aggregate Functions Many (but not all) aggregate functions that take a single argument accept these clauses: • DISTINCT and UNIQUE, which are synonymous, cause an aggregate function to consider only distinct values of the argument expression. The syntax diagrams for aggregate functions in this chapter use the keyword DISTINCT for simplicity. • ALL causes an aggregate function to consider all values, including all duplicates.
  • 13. Oracle Database, SQL13 Aggregate Functions SUM( [ALL | DISTINCT] expression ) AVG( [ALL | DISTINCT] expression ) COUNT( [ALL | DISTINCT] expression ) COUNT(*) MAX(expression) MIN(expression)
  • 14. Oracle Database, SQL14 Sum SUM(ALL/DISTINCT expr) Returns the sum value of expr. SELECT SUM(salary), SUM(ALL salary), SUM(DISTINCT salary) FROM employees;
  • 15. Oracle Database, SQL15 Avg AVG(ALL/DISTINCT expr) Returns the average value of expr. SELECT AVG(salary), AVG(ALL salary), AVG(DISTINCT salary) FROM employees;
  • 16. Oracle Database, SQL16 Count COUNT(*) OR COUNT(ALL/DISTINCT expr) Returns the number of rows in the query. If you specify expr then count ignore nulls. If you specify the asterisk (*), this function returns all rows, including duplicates and nulls. COUNT never returns null. SELECT COUNT(manager_id), COUNT(*), COUNT(ALL manager_id), COUNT(DISTINCT manager_id) FROM employees;
  • 17. Oracle Database, SQL17 Max MAX(ALL/DISTINCT expr) Returns the maximum value of expr. SELECT MAX(salary), MAX(ALL salary), MAX(DISTINCT salary) FROM employees;
  • 18. Oracle Database, SQL18 Min MIN(ALL/DISTINCT expr) Returns the minimum value of expr. SELECT MIN(salary), MIN(ALL salary), MIN(DISTINCT salary) FROM employees;
  • 19. Oracle Database, SQL19 Aggregate Functions A WHERE clause is used to filter rows BEFORE the GROUPING action A HAVING clause filters rows AFTER the GROUPING action SELECT department_id, SUM(salary) FROM employees WHERE department_id <> 100 GROUP BY department_id HAVING SUM(salary) >= 15000;
  • 20. CONTACTS 20 Gurpreet Singh Senior Software Engineer CUG. 2142 M. +91-9803723925 Gurpreet.singh2@soprasteria.com Oracle Database, SQL