0% found this document useful (0 votes)
23 views

Unit4 Rdbms

Oracle Database is a relational database management system produced and marketed by Oracle Corporation. It was one of the first databases designed for enterprise computing and data warehousing. Oracle Database is available in various editions - Enterprise Edition, Standard Edition, Express Edition, and Personal Edition - with different features and licensing. It supports a variety of platforms and uses SQL queries to interact with stored data.

Uploaded by

maskguy001
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Unit4 Rdbms

Oracle Database is a relational database management system produced and marketed by Oracle Corporation. It was one of the first databases designed for enterprise computing and data warehousing. Oracle Database is available in various editions - Enterprise Edition, Standard Edition, Express Edition, and Personal Edition - with different features and licensing. It supports a variety of platforms and uses SQL queries to interact with stored data.

Uploaded by

maskguy001
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 24

Unit-4

Introduction to RDBMS software-oracle


Introduction
Oracle database is a relational database management system (RDBMS) from
Oracle Corporation.A database refers to the organized collection of structured
data stored electronically in a device. It allows us to access, manage, and find
relevant information frequently. The flat file structure was extensively used to
store data before the database system was invented. The relational database
approach becomes popular in comparison to the flat file model because it
eliminates redundant data. For example, suppose we have an employee and
contact information stored in the same file. In such a case, the employees with
multiple contacts will show up in many rows.

The RDBMS system manages the relational data. Oracle Database is the most
famous relational database system (RDBMS) because it shares the largest part of a
market among other relational databases. Some other popular relational databases
are MySQL, DB2, SQL Server, PostgreSQL, etc.

Oracle database
Oracle database is a relational database management system. It is also
called OracleDB, or simply Oracle. It is produced and marketed by Oracle
Corporation. It was created in 1977 by Lawrence Ellison and other engineers. It
is one of the most popular relational database engines in the IT market for storing,
organizing, and retrieving data.

Oracle database was the first DB that designed for enterprise grid computing and
data warehousing. Enterprise grid computing provides the most flexible and cost-
effective way to manage information and applications. It uses SQL queries as a
language for interacting with the database.

Editions of Oracle database

Oracle database is compatible with a wide range of platforms such as Windows,


UNIX, Linux, and macOS. It supports several operating systems like IBM AIX,
HP-UX, Linux, Microsoft Windows Server, Solaris, SunOS, macOS, etc. In the
late 1990s, Oracle began supporting open platforms like GNU/Linux.

The following is a list of Oracle database editions in order of priority:

o Enterprise Edition: It is the most robust and secure edition. It offers all
features, including superior performance and security.
o Standard Edition: It provides the base functionality for users that do not
require Enterprise Edition's robust package.
o Express Edition (XE): It is the lightweight, free and limited Windows, and
Linux edition.
o Oracle Lite: It is designed for mobile devices.

Personal Edition: It's comparable to the Enterprise Edition but without the
Oracle Real Application Clusters feature.

Oracle Database Enterprise Edition

Oracle Database Enterprise Edition provides performance, availability,


scalability, and security for developing applications such as high-volume online
transaction processing (OLTP) applications, query-intensive data warehouses,
and demanding Internet applications. Oracle Database Enterprise Edition can be
enhanced with the purchase of Oracle Database options and Oracle
management packs.

Secure and flexible enterprise databases


Enterprise Database Service allows you to develop and run enterprise applications
in OCI environments using the following features found in all Enterprise Database
Service subscriptions.

Features
 Oracle Database version 12.1, 12.2, 19c, and 21c support with converged database
capabilities enables you to run any database workload with all supported data types
 Multilayered security including always-on transparent database encryption that
protects your databases at the source
 Advanced database security and management technologies, such as Oracle Data
Safe, Data Masking Pack, Diagnostics Pack, and Tuning Pack, help you to meet
enterprise service level agreements
 Fast provisioning of single-node virtual machine database systems for Oracle
Database with logical volume manager increases your developers’ productivity
 Flexible and scalable Oracle Database license consumption allows you to meet
application needs while minimizing costs
 Built-in automation increases your productivity by simplifying database lifecycle
management
 Oracle Machine Learning, Graph, and Spatial features are included at no cost,
allowing developers to add innovative, in-database, analytic capabilities to existing
applications
 Hybrid Columnar Compression reduces storage requirements for your data
warehouses
 Oracle Database Zero Data Loss Autonomous Recovery Service simplifies data
protection and eliminates data loss exposure, providing low-cost resiliency against
ransomware attacks and human errors.
 Bring-your-own-license (BYOL) subscriptions enable you to leverage existing
database licenses.
Oracle Database Personal Edition

Oracle Database Personal Edition supports single-user development and


deployment environments that require full compatibility with Oracle Database
Standard Edition 2 and Oracle Database Enterprise Edition.
Includes all of the components that are included with Enterprise Edition, as well as
all Oracle Database options, with the exception of the Oracle RAC One Node and
Oracle Real Application Clusters options,which cannot be used with Personal
Edition. Personal Edition is available on Linux and Windows platforms only.
Oracle management packs cannot be used with Personal Edition.
Features

 Basically, with PE you can use all database features except for RAC,
RAC One Node and the DB Management Packs.
 Oracle Database Express Edition (Oracle Database XE) is an entry-
level edition of Oracle Database that is quick to download, simple to
install and manage, and is free to develop, deploy, and distribute.
 Oracle Database XE makes it easy to upgrade to the other editions of
Oracle without costly and complex migrations.
 . Oracle Database XE can be installed on any size machine with any
number of CPUs, stores up to 4GB of user data, using up to 1GB of
memory, and using only one CPU on the host machine. Support is
provided by an online forum.
 Oracle Database Personal Edition Oracle Database Personal Edition
supports single-user development and deployment environments that
require full compatibility with Oracle Database Standard Edition One,
Oracle Database Standard Edition, and Oracle Database Enterprise
Edition.
 Personal Edition includes all of the components that are included with
Enterprise Edition, as well as all of the options that are available with
Enterprise Edition, with the exception of the Oracle Real Application
Clusters option, which cannot be used with Personal Edition. Personal
Edition is available on Windows platforms only. The Management
Packs are not included in Personal Edition.

Introduction to Oracle data types

Data types are used to represent the nature of the data that can be stored in the
database table. For example, in a particular column of a table, if we want to store a
string type of data then we will have to declare a string data type of this column.

Data types mainly classified into three categories for every database.

o String Data types


o Numeric Data types
o Date and time Data types

Data Types in MySQL, SQL Server and Oracle Databases

MySQL Data Types

A list of data types used in MySQL database. This is based on MySQL 8.0.
MySQL String Data Types

CHAR(Size) It is used to specify a fixed length string that can contain numbers, letters, and special characters.
Its size can be 0 to 255 characters. Default is 1.

VARCHAR(Size) It is used to specify a variable length string that can contain numbers, letters, and special
characters. Its size can be from 0 to 65535 characters.

BINARY(Size) It is equal to CHAR() but stores binary byte strings. Its size parameter specifies the column length
in the bytes. Default is 1.

VARBINARY(Size) It is equal to VARCHAR() but stores binary byte strings. Its size parameter specifies the
maximum column length in bytes.

TEXT(Size) It holds a string that can contain a maximum length of 255 characters.

TINYTEXT It holds a string with a maximum length of 255 characters.

MEDIUMTEXT It holds a string with a maximum length of 16,777,215.

LONGTEXT It holds a string with a maximum length of 4,294,967,295 characters.

ENUM(val1, val2, val3,...) It is used when a string object having only one value, chosen from a list of possible values. It
contains 65535 values in an ENUM list. If you insert a value that is not in the list, a blank value
will be inserted.

SET( val1,val2,val3,....) It is used to specify a string that can have 0 or more values, chosen from a list of possible values.
You can list up to 64 values at one time in a SET list.

BLOB(size) It is used for BLOBs (Binary Large Objects). It can hold up to 65,535 bytes.

MySQL Numeric Data Types

BIT(Size) It is used for a bit-value type. The number of bits per value is specified in size. Its size can be 1 to 64.
The default value is 1.

INT(size) It is used for the integer value. Its signed range varies from -2147483648 to 2147483647 and unsigned
range varies from 0 to 4294967295. The size parameter specifies the max display width that is 255.

INTEGER(siz It is equal to INT(size).


e)

FLOAT(size, It is used to specify a floating point number. Its size parameter specifies the total number of digits. The
d) number of digits after the decimal point is specified by d parameter.

FLOAT(p) It is used to specify a floating point number. MySQL used p parameter to determine whether to use
FLOAT or DOUBLE. If p is between 0 to24, the data type becomes FLOAT (). If p is from 25 to 53,
the data type becomes DOUBLE().
DOUBLE(size, It is a normal size floating point number. Its size parameter specifies the total number of digits. The
d) number of digits after the decimal is specified by d parameter.

DECIMAL(siz It is used to specify a fixed point number. Its size parameter specifies the total number of digits. The
e, d) number of digits after the decimal parameter is specified by d parameter. The maximum value for the
size is 65, and the default value is 10. The maximum value for d is 30, and the default value is 0.

DEC(size, d) It is equal to DECIMAL(size, d).

MySQL Date and Time Data Types

DATE It is used to specify date format YYYY-MM-DD. Its supported range is from '1000-01-01' to '9999-12-31'.

DATETIME(fsp) It is used to specify date and time combination. Its format is YYYY-MM-DD hh:mm:ss. Its supported range is
from '1000-01-01 00:00:00' to 9999-12-31 23:59:59'.

TIMESTAMP(fsp It is used to specify the timestamp. Its value is stored as the number of seconds since the Unix epoch('1970-01-
) 01 00:00:00' UTC). Its format is YYYY-MM-DD hh:mm:ss. Its supported range is from '1970-01-01 00:00:01'
UTC to '2038-01-09 03:14:07' UTC.

TIME(fsp) It is used to specify the time format. Its format is hh:mm:ss. Its supported range is from '-838:59:59' to
'838:59:59'

YEAR It is used to specify a year in four-digit format. Values allowed in four digit format from 1901 to 2155, and
0000.

Commercial query language


SQL(Structured query language)
Structure Query Language(SQL) is a database query language used for storing and
managing data in Relational DBMS. SQL was the first commercial language
introduced for E.F Codd's Relational model of database. Today almost all
RDBMS(MySql, Oracle, Infomix, Sybase, MS Access) use SQL as the standard
database query language. SQL is used to perform all types of data operations in
RDBMS.

o SQL stands for Structured Query Language. It is used for storing and
managing data in relational database management system (RDMS).
o It is a standard language for Relational Database System. It enables a user to
create, read, update and delete relational databases and tables.
o All the RDBMS like MySQL, Informix, Oracle, MS Access and SQL Server
use SQL as their standard database language.
o SQL allows users to query the database in a number of ways, using English-
like statements.

Rules:

SQL follows the following rules:

o Structure query language is not case sensitive. Generally, keywords of SQL


are written in uppercase.
o Statements of SQL are dependent on text lines. We can use a single SQL
statement on one or multiple text line.
o Using the SQL statements, you can perform most of the actions in a
database.
o SQL depends on tuple relational calculus and relational algebra.

SQL process:

o When an SQL command is executing for any RDBMS, then the system
figure out the best way to carry out the request and the SQL engine
determines that how to interpret the task.
o In the process, various components are included. These components can be
optimization Engine, Query engine, Query dispatcher, classic, etc.
o All the non-SQL queries are handled by the classic query engine, but SQL
query engine won't handle logical files.
PL/SQL

PL/SQL tutorial provides basic and advanced concepts of SQL. Our PL/SQL tutorial is
designed for beginners and professionals.

PL/SQL is a block structured language that can have multiple blocks in it.

Our PL/SQL tutorial includes all topics of PL/SQL language such as conditional
statements, loops, arrays, string, exceptions, collections, records, triggers, functions,
procedures, cursors etc. There are also given PL/SQL interview questions and quizzes to
help you better understand the PL/SQL language.

SQL stands for Structured Query Language i.e. used to perform operations on the
records stored in database such as inserting records, updating records, deleting records,
creating, modifying and dropping tables, views etc.

What is PL/SQL

PL/SQL is a block structured language. The programs of PL/SQL are logical


blocks that can contain any number of nested sub-blocks. Pl/SQL stands for
"Procedural Language extension of SQL" that is used in Oracle. PL/SQL is
integrated with Oracle database (since version 7). The functionalities of PL/SQL
usually extended after each release of Oracle database. Although PL/SQL is
closely integrated with SQL language, yet it adds some programming constraints
that are not available in SQL.

PL/SQL Functionalities

PL/SQL includes procedural language elements like conditions and loops. It allows
declaration of constants and variables, procedures and functions, types and variable
of those types and triggers. It can support Array and handle exceptions (runtime
errors). After the implementation of version 8 of Oracle database have included
features associated with object orientation. You can create PL/SQL units like
procedures, functions, packages, types and triggers, etc. which are stored in the
database for reuse by applications.

With PL/SQL, you can use SQL statements to manipulate Oracle data and flow of
control statements to process the data.

The PL/SQL is known for its combination of data manipulating power of SQL with
data processing power of procedural languages. It inherits the robustness, security,
and portability of the Oracle Database.

PL/SQL is not case sensitive so you are free to use lower case letters or upper case
letters except within string and character literals.

DDL Commands in SQL

DDL is an abbreviation of Data Definition Language.

The DDL Commands in Structured Query Language are used to create and modify
the schema of the database and its objects. The syntax of DDL commands is
predefined for describing the data. The commands of Data Definition Language
deal with how the data should exist in the database.

Following are the five DDL commands in SQL:

1. CREATE Command
2. DROP Command
3. ALTER Command
4. TRUNCATE Command
5. RENAME Command

CREATE Command

CREATE is a DDL command used to create databases, tables, triggers and other
database objects.

Examples of CREATE Command in SQL

Example 1: This example describes how to create a new database using the
CREATE DDL command.

Syntax to Create a Database:

1. CREATE Database Database_Name;

Suppose, you want to create a Books database in the SQL database. To do this, you
have to write the following DDL Command:

1. Create Database Books;


Example 2: This example describes how to create a new table using the
CREATE DDL command.

Syntax to create a new table:

1. CREATE TABLE table_name


(
column_Name1 data_type ( size of the column ) ,
column_Name2 data_type ( size of the column) ,
column_Name3 data_type ( size of the column) ,
...
column_NameN data_type ( size of the column )
);

Suppose, you want to create a Student table with five columns in the SQL
database. To do this, you have to write the following DDL command:
CREATE TABLE Student
(
Roll_No. Int ,
First_Name Varchar (20) ,
Last_Name Varchar (20) ,
Age Int ,
Marks Int ,
);

Example 3: This example describes how to create a new index using the CREATE
DDL command.

Syntax to Create a new index:

1. CREATE INDEX Name_of_Index ON Name_of_Table (column_name_1 , colum


n_name_2 , … . , column_name_N);

Let's take the Student table:

Stu_Id Name Marks City State

100 Abhay 80 Noida U.P

101 Sushil 75 Jaipur Rajasthan

102 Ankit 90 Gurgaon Haryana

103 Yogesh 93 Lucknow U.P

Suppose, you want to create an index on the combination of


the City and State field of the Student table. For this, we have to use the
following DDL command:

1. CREATE INDEX index_city_State ON Employee (Emp_City, Emp_State);

Example 4: This example describes how to create a trigger in the SQL


database using the DDL CREATE command.

Syntax to create a trigger:


CREATE TRIGGER [trigger_name]
[ BEFORE | AFTER ]
{ INSERT | UPDATE | DELETE }
ON [table_name] ;

DROP Command

DROP is a DDL command used to delete/remove the database objects from the
SQL database. We can easily remove the entire table, view, or index from the
database using this DDL command.

Examples of DROP Command in SQL


Example 1: This example describes how to remove a database from the SQL
database.

Syntax to remove a database:

1. DROP DATABASE Database_Name;

Suppose, you want to delete the Books database from the SQL database. To do
this, you have to write the following DDL command:

DROP DATABASE Books;

Example 2: This example describes how to remove the existing table from the
SQL database.

Syntax to remove a table:

DROP TABLE Table_Name;

Suppose, you want to delete the Student table from the SQL database. To do this,
you have to write the following DDL command:

DROP TABLE Student;

ALTER Command
ALTER is a DDL command which changes or modifies the existing structure of
the database, and it also changes the schema of database objects.

We can also add and drop constraints of the table using the ALTER command.

Examples of ALTER Command in SQL

Example 1: This example shows how to add a new field to the existing table.

Syntax to add a newfield in the table:

ALTER TABLE name_of_table ADD column_name column_definition;

Suppose, you want to add the 'Father's_Name' column in the existing Student table.
To do this, you have to write the following DDL command:

ALTER TABLE Student ADD Father's_Name Varchar(60);

TRUNCATE Command

TRUNCATE is another DDL command which deletes or removes all the records
from the table.

This command also removes the space allocated for storing the table records.

Syntax of TRUNCATE command

1. TRUNCATE TABLE Table_Name;

Example

Suppose, you want to delete the record of the Student table. To do this, you have to
write the following TRUNCATE DDL command:

TRUNCATE TABLE Student;

The above query successfully removed all the records from the student table. Let's
verify it by using the following SELECT statement:

SELECT * FROM Student;


RENAME Command

RENAME is a DDL command which is used to change the name of the database
table.

Syntax of RENAME command

RENAME TABLE Old_Table_Name TO New_Table_Name;

Example

RENAME TABLE Student TO Student_Details ;

This query changes the name of the table from Student to Student_Details.

DML Commands in SQL


DML is an abbreviation of Data Manipulation Language.

The DML commands in Structured Query Language change the data present in the
SQL database. We can easily access, store, modify, update and delete the existing
records from the database using DML commands.

Following are the four main DML commands in SQL:

1. SELECT Command
2. INSERT Command
3. UPDATE Command
4. DELETE Command

SELECT DML Command

SELECT is the most important data manipulation command in Structured Query


Language. The SELECT command shows the records of the specified table. It also
shows the particular record of a particular column by using the WHERE clause.

Syntax of SELECT DML command

1. SELECT column_Name_1, column_Name_2, ….., column_Name_N FROM Na


me_of_table;
Here, column_Name_1, column_Name_2, ….., column_Name_N are the
names of those columns whose data we want to retrieve from the table.

If we want to retrieve the data from all the columns of the table, we have to
use the following SELECT command:

1. SELECT * FROM table_name;

Examples of SELECT Command

Example 1: This example shows all the values of every column from the
table.

1. SELECT * FROM Student;

This SQL statement displays the following values of the student table:

Student_ID Student_Name Student_Marks

BCA1001 Abhay 85

BCA1002 Anuj 75

BCA1003 Bheem 60

BCA1004 Ram 79

BCA1005 Sumit 80

Example 2: This example shows all the values of a specific column from
the table.

1. SELECT Emp_Id, Emp_Salary FROM Employee;

This SELECT statement displays all the values


of Emp_Salary and Emp_Id column of Employee table:
Emp_Id Emp_Salary

201 25000

202 45000

203 30000

204 29000

205 40000

INSERT DML Command

INSERT is another most important data manipulation command in Structured


Query Language, which allows users to insert data in database tables.

Syntax of INSERT Command

INSERT INTO TABLE_NAME ( column_Name1 , column_Name2 , column_Name3 , .... colu


mn_NameN ) VALUES (value_1, value_2, value_3, .... value_N ) ;

Examples of INSERT Command

Example 1: This example describes how to insert the record in the database table.

Let's take the following student table, which consists of only 2 records of the student.

Stu_Id Stu_Name Stu_Marks Stu_Age

101 Ramesh 92 20

201 Jatin 83 19

Suppose, you want to insert a new record into the student table. For this, you have to write the
following DML INSERT command:

1. INSERT INTO Student (Stu_id, Stu_Name, Stu_Marks, Stu_Age) VALUES (104, Anmol, 89,
19);
UPDATE DML Command

UPDATE is another most important data manipulation command in Structured Query Language,
which allows users to update or modify the existing data in database tables.

Syntax of UPDATE Command

1. UPDATE Table_name SET [column_name1= value_1, ….., column_nameN = value_N] WHE


RE CONDITION;

Here, 'UPDATE', 'SET', and 'WHERE' are the SQL keywords, and 'Table_name' is the name of
the table whose values you want to update.

Examples of the UPDATE command

Example 1: This example describes how to update the value of a single field.

Let's take a Product table consisting of the following records:

Product_Id Product_Name Product_Price Product_Quantity

P101 Chips 20 20

P102 Chocolates 60 40

P103 Maggi 75 5

P201 Biscuits 80 20

P203 Namkeen 40 50

Suppose, you want to update the Product_Price of the product whose Product_Id is P102. To do
this, you have to write the following DML UPDATE command:

1. UPDATE Product SET Product_Price = 80 WHERE Product_Id = 'P102' ;

Example 2: This example describes how to update the value of multiple fields of the
database table.

Let's take a Student table consisting of the following records:

Stu_Id Stu_Name Stu_Marks Stu_Age


101 Ramesh 92 20

201 Jatin 83 19

202 Anuj 85 19

203 Monty 95 21

102 Saket 65 21

103 Sumit 78 19

104 Ashish 98 20

DELETE DML Command

DELETE is a DML command which allows SQL users to remove single or


multiple existing records from the database tables.

This command of Data Manipulation Language does not delete the stored data
permanently from the database. We use the WHERE clause with the DELETE
command to select specific rows from the table.

Syntax of DELETE Command

DELETE FROM Table_Name WHERE condition;

Examples of DELETE Command

Example 1: This example describes how to delete a single record from the
table.

Let's take a Product table consisting of the following records:

Product_Id Product_Name Product_Price Product_Quantity

P101 Chips 20 20

P102 Chocolates 60 40
P103 Maggi 75 5

P201 Biscuits 80 20

P203 Namkeen 40 50

Suppose, you want to delete that product from the Product table whose Product_Id
is P203. To do this, you have to write the following DML DELETE command:

DELETE FROM Product WHERE Product_Id = 'P202' ;

Example 2: This example describes how to delete the multiple records or rows
from the database table.

Let's take a Student table consisting of the following records:

Stu_Id Stu_Name Stu_Marks Stu_Age

101 Ramesh 92 20

201 Jatin 83 19

202 Anuj 85 19

203 Monty 95 21

102 Saket 65 21

103 Sumit 78 19

104 Ashish 98 20

Suppose, you want to delete the record of those students whose Marks is greater
than 70. To do this, you have to write the following DML Update command:

DELETE FROM Student WHERE Stu_Marks > 70 ;

SQL functions
Functions are methods used to perform data operations. SQL has many in-built
functions used to perform string concatenations, mathematical calculations etc.

SQL functions are categorized into the following two categories:

1. Aggregate Functions
2. Scalar Functions

Aggregate SQL Functions


The Aggregate Functions in SQL perform calculations on a group of values and then
return a single value. Following are a few of the most commonly used Aggregate
Functions:

Function Description
SUM() Used to return the sum of a group of values.
Returns the number of rows either based on
COUNT()
a condition, or without a condition.
Used to calculate the average value of a
AVG()
numeric column.
This function returns the minimum value of
MIN()
a column.
MAX() Returns a maximum value of a column.
FIRST() Used to return the first value of the column.
This function returns the last value of the
LAST()
column.
Let us look into each one of the above functions in depth. For your better
understanding, I will be considering the following table to explain to you all the
examples.

StudentID StudentName Marks


1 Sanjay 64
2 Varun 72
3 Akash 45
4 Rohit 86
5 Anjali 92

SUM()

Used to return a total sum of numeric column which you choose.


Syntax:

SELECT SUM(ColumnName)
FROM TableName;
Example:

Write a query to retrieve the sum of marks of all students from the Students table.

SELECT SUM(Marks)
FROM Students;

Output:

359

COUNT()

Returns the number of rows present in the table either based on some condition or
without any condition.

Syntax:

SELECT COUNT(ColumnName)FROM TableName


WHERE Condition;

Example:

Write a query to count the number of students from the Students table.

SELECT COUNT(StudentID)
FROM Students;

Output:

Example:

Write a query to count the number of students scoring marks > 75 from the Students
table.
SELECT COUNT(StudentID)
FROM Students
WHERE Marks >75;

Output:

AVG()

This function is used to return the average value of a numeric column.

Syntax:

SELECT AVG(ColumnName)
FROM TableName;
Example:

Write a query to calculate the average marks of all students from the Students
table.

SELECT AVG(Marks)
FROM Students;

Output:

71.8

MIN()

Used to return the minimum value of a numeric column.

syntax:

SELECT MIN(ColumnName)
FROM TableName;
Example:

Write a query to retrieve the minimum marks out of all students from the Students table.

SELECT MIN(Marks)
FROM Students;
Output:

MAX()

Returns the maximum value of a numeric column.

Syntax:

SELECT MAX(ColumnName)FROM TableName;

Example:

Write a query to retrieve the maximum marks out of all students from the Students table.

SELECT MAX(Marks)
FROM Students;
Output:

FIRST()

This function returns the first value of the column which you choose.

Syntax:

SELECT FIRST(ColumnName)
FROM TableName;
Example:

Write a query to retrieve the marks of the first student.

SELECT FIRST(Marks)
FROM Students;
Output:

LAST()

Used to return the last value of the column which you choose.

Syntax:

SELECT LAST(ColumnName)
FROM TableName;
Example:

Write a query to retrieve the marks of the last student.


SELECT LAST(Marks)
FROM Students;
Output: 92

Well, with that we come to an end to SQL Aggregate Functions. Next in this article on
SQL Functions, let us understand the various Scalar Functions.

3.

You might also like