SlideShare a Scribd company logo
INTRODUCTION
PL/SQL
Content
• PL/SQL Introduction
• What is Data
• What is information
• Database
• Database of management studies
• Application of DBMS
• Types of DBMS
• SQL
• SQL Command
• Sample SQL creating table
PL/SQL stands for “Procedural Language extensions to the structured
query Language”. SQL is a popular language for both querying and updating data in
the relational database management systems (RDBMS). PL/SQL adds many
procedural constructs to SQL language to overcome some limitations of SQL.
PL/SQL
One can create a PL/SQL unit such as procedures, functions, packages, triggers,
and types, which are stored in the database for reuse by applications.
What is Data
• A collection of raw facts and figures
• Raw Material that can be processed by
computing machine
• A collection of facts from which conclusions
may be drawn
• Data can be represented in the form of
numbers and words which can be stored in
computer’s language
What is information
• Systematic and meaningful form of data
• Knowledge acquired through study or experience
• Information helps human beings in their decision making
Database
• A repository of logically related and similar data
• An organized collection of related information so that it
can easily be accessed, managed and updated
Eg:
• Dictionary
• Airline Database
• Student Database
• Library
• Railways Timetable
• YouTube(All Songs of Rahul Vaidya)
What is DBMS
• DBMS stands for Database Management System
• DBMS is a software system for creating , organizing and managing
the database
• It provides an environment to the user to perform operations on the
database for creation, insertion, deletion, updating and retrieval of
data
Why Use a DBMS
• Data independence and efficient access
• Reduced application development time
• Data integrity and security
• Uniform data administration
• Concurrent access, recovery from crashes.
DifferentpeoplebehindDBMS
• Database Administrator(DBA)- The DBA is responsible for authorizing access to the database, for
coordinating and monitoring its use, an for acquiring software and hardware resources as need
• Database Designers - Database designers are responsible for identifying the data to be stored in the database
or choosing appropriate structures to represent and store this data. These tasks are mostly undertaken before
the database is actually implemented and populated with data
• End Users –
• Casual end users,
• naïve or parametric end users,
• Sophisticated end users,
• stand-alone users
• System Analysts and Application Programmers – Application programmers implement these specifications
as programs, then they test, debug, document, and maintain theses canned transactions
• DBMS Designers and implementers : are persons who design and implement the DBMS modules and
interfaces as a software package.
• Tool Developers : They include package for database design, performance monitoring, natural language or
graphical interfaces, prototyping ,simulation , and test data generation
• Operators and Maintenance Personnel : are the system administration personnel who are responsible for
the actual running and maintenance of the hardware and software environment for the database system
Application of DBMS
Sector Use of DBMS
Banking For customer information, account activities, payments,
deposits, loans, etc.
Airlines For reservations and schedule information.
Universities For student information, course registrations, colleges and
grades.
Telecommunication It helps to keep call records, monthly bills, maintaining
balances, etc.
Finance For storing information about stock, sales, and purchases of
financial instruments like stocks and bonds.
Sales Use for storing customer, product & sales information.
Manufacturing It is used for the management of supply chain and for tracking
production of items. Inventories status in warehouses.
HR Management For information about employees, salaries, payroll, deduction,
generation of paychecks, etc.
Types of DBMS
Hierarchical DBMS
In a Hierarchical database, model data is organized in a tree-like structure. Data is Stored Hierarchically (top down or bottom
up) format. Data is represented using a parent-child relationship. In Hierarchical DBMS parent may have many children, but
children have only one parent.
Network Model
The network database model allows each child to have multiple parents. It helps you to address the need to model more complex
relationships like as the orders/parts many-to-many relationship. In this model, entities are organized in a graph which can be
accessed through several paths.
Relational model
Relational DBMS is the most widely used DBMS model because it is one of the easiest. This model is based on normalizing data
in the rows and columns of the tables. Relational model stored in fixed structures and manipulated using SQL.
Object-Oriented Model
In Object-oriented Model data stored in the form of objects. The structure which is called classes which display data within it. It
defines a database as a collection of objects which stores both data members values and operations.
What is SQL
SQL is used to communicate with a database. According to ANSI (American
National Standards Institute), it is the standard language for
relational database management systems. SQL statements are used to perform
tasks such as update data on a database, or retrieve data from a database.
Fact of SQL
SQL was developed at IBM by Donald D. Chamberlin
and Raymond F Boyce in the early 1970s
It was initially called SEQUEL(Structured English Query
Language)
SQL is a powerful language that uses simple English
sentences
SQL is a Declarative Language
• Structure Query Language(SQL) is a database query
language used for storing and managing data in Relational
DBMS.
• 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.
SQL Command
DDL: Data Definition Language
Data Definition Language (DDL) statement are used to define the database structure or
schema
Some example
CREATE- to create objects in the database
ALTER- alters the structure of the database
DROP- delete objects from the database
TRUNCATE- remove all records from a table, including all space allocated for the
records are removed
COMMENT – add comments to the data dictionary
RENAME-rename an object
DML: Data Manipulation Language
Data Manipulation Language(DML) statement are used for managing data
within schema objects
SELECT- Retrieve data from the a database
INSERT- Insert data into a table
UPDATE- Updates existing data within a table
DELETE - deletes all records from a table, the space for the records remain
• TCL: Transaction Control Language
(These commands are to keep a check on other commands and their
affect on the database.(commit, rollback)
• DCL: Data Control Language(grant: permission)
• DQL: Data Query Language (select)
create table students(regno number(10), name varchar2(15), major varchar2(8));
desc students;
insert into students values('03','naveen','maths')
insert into students values('04','naveen','maths')
insert into students values('05','naveen','maths')
select * from students
Select regno ,major from students
delete students
alter table studentss rename to stud;
drop table stud;
desc stud;
Sample SQL creating table
SQL and PL/SQL execution
STEP-01
STEP-02
STEP-03
STEP-04
STEP-05
STEP-06
STEP-07
STEP-08
STEP-09
STEP-10
STEP-11
Exercise-01
1.Write a SQL statement to display all the information of all salesmen. Sample table:
salesman
Exercise-01- Solution
1.Write a SQL statement to display all the information of all salesmen. Sample table:
salesman
create table salesmen(sales_id number(10), name varchar(12), city varchar(10),
commission number(20));
insert into salesmen values(500,'james Hoog','New york',0.15);
Exercise-02
Table name : workers
Solution
create table Worker1(worker_id number(10),firstname char(23),lastname char(23),salary
number(15),department char(24));
insert into Worker1 values (001, 'Monika', 'Arora', 100000,'HR');
select * from Worker1;
Disadvantages of SQL
• SQL doesn’t provide the programmers with a technique of condition checking, looping and
branching.
• SQL statements are passed to Oracle engine one at a time which increases traffic and decreases
speed.
• SQL has no facility of error checking during manipulation of data.
• For SQL need training to an excess database.
• SQL can be handled by an expert user or programmer.
• It occupies some space i.e extra memory location for each record.
• It is a command based language.
• It is platform dependent language.
Introduction to PL/SQL
PL/SQL stands for “Procedural Language extensions to the structured Query Language
A procedural language is a type of computer programming language that specifies a series of well-structured steps and procedures within its
programming context to compose a program. It contains a systematic order of statements, functions and commands to complete a
computational task or program.
The PL/SQL programming language was developed by Oracle Corporation in the late 1980s as procedural
extension language for SQL and the Oracle relational database.
Following are certain notable facts about PL/SQL −
• PL/SQL is a completely portable, high-performance transaction-processing language.
• PL/SQL provides a built-in, interpreted and OS independent programming environment.
• PL/SQL can also directly be called from the command-line SQL*Plus interface.
• Direct call can also be made from external programming language calls to database.
• PL/SQL's general syntax is based on that of ADA and Pascal programming language.
• Apart from Oracle, PL/SQL is available in TimesTen in-memory database and IBM DB2.
Features of PL/SQL
Portable:
PL/SQL applications can be executed with all types of operating system where we have oracle
installed.
Efficient:
All sorts of calculations can be efficiently performed by PL/SQL without the use of oracle
engine. This improves transaction performance.
Error-checking
PL/SQL allows error-checking and displays user-friendly messages when error occurs.
Development tool:
PL/SQL supports execution of SQL statements along with the functionality of variable declaration,
conditional statements, looping and branching, procedures, functions and triggers.
Exception Handling:
PL/SQL code is capable of handling exceptions that can affect the flow of program, hence helps in
making the code more reliable
• For example, consider we have a School Management System database and
we want to see the list of students who took admission in last 5 years in
school and the fees deposited by them.
• And at the same time we want to add the total amount of salary money given
to the teaching and non-teaching staff. We cannot fetch these records by just
executing SQL queries, we might be able to gather the data but it would
require multiple SQL queries.
• On the other hand if we use PL/SQL, we can write procedures or methods in
PL/SQL program to execute complex logic on a database.
• Another advantage is that we can also detect errors easily as it displays user-
friendly messages and it even supports exception handling.
SQL PL/SQL
SQL is a single query that is used to
perform DML and DDL operations.
PL/SQL is a block of codes that used
to write the entire program blocks/
procedure/ function, etc.
It is declarative, that defines what
needs to be done, rather than how
things need to be done.
PL/SQL is procedural that defines
how the things needs to be done.
Execute as a single statement. Execute as a whole block.
Mainly used to manipulate data. Mainly used to create an application.
Cannot contain PL/SQL code in it.
It is an extension of SQL, so it can
contain SQL inside it.
Differences between SQL and PL/SQL:
PL/SQL architecture
PL/SQL Architecture
PL/SQL Architecture
Architecture of PL/SQL
The PL/SQL architecture mainly consists of following three components:
– PL/SQL block
– PL/SQL Engine
– Database Server
PL/SQL block
This is the component which has the actual PL/SQL code.
This consists of different sections to divide the code logically (declarative section for declaring
purpose, execution section for processing statements, exception handling section for handling
errors)
It also contains the SQL instruction that used to interact with the database server.
All the PL/SQL units are treated as PL/SQL blocks, and this is the starting stage of the architecture
which serves as the primary input
Following are the different type of PL/SQL units.
Anonymous Block
Function
Library
Procedure
Package Body
Package Specification
Trigger
Type
Type Body
PL/SQL Engine
• PL/SQL engine is the component where the actual processing of the codes takes place.
• PL/SQL engine separates PL/SQL units and SQL part in the input.
• The separated PL/SQL units will be handled by the PL/SQL engine itself.
• The SQL part will be sent to database server where the actual interaction with database takes place.
• It can be installed in both database server and in the application server
Database Server:
• This is the most important component of Pl/SQL unit which stores the data.
• The PL/SQL engine uses the SQL from PL/SQL units to interact with the database server.
• It consists of SQL executor which parses the input SQL statements and execute the same.
Typically, each block performs a logical action in the
program. A block has the following structure:
DECLARE
• Declare section starts with DECLARE keyword in which variables, constants, records as cursors can be declared which stores
data temporarily. It basically consists definition of PL/SQL identifiers. This part of the code is optional.
EXECUTION SECTION
• Execution section starts with BEGIN and ends with END keyword.
• This is a mandatory section and here the program logic is written to perform any task like loops and conditional statements.
• It should have at least one executable line of code, which may be just a NULL command to indicate that nothing should be
executed.
EXCEPTION
• Exception section starts with EXCEPTION keyword.
• This section is optional which contains statements that are executed when a run-time error occurs.
• Any exceptions can be handled in this section.
PL/SQL SET Serveroutput ON
• Whenever you start Oracle SQL (PL/SQL) at that time you must have to write the "SET Serveroutput ON"
command.
• PL/SQL program execution into Oracle engine so we always required to get serveroutput result and display
into the screen otherwise result can't be display.
PL/SQL anonymous block example
• The following example shows a simple PL/SQL anonymous block with one executable
section.
To run the code from the SQL command line, you may need to type / at the beginning of the first
blank line after the last line of the code.
When the above code is executed at the SQL prompt, it produces the following result −
Hello There
PL/SQL procedure successfully completed.
The 'Hello World' Example
The PL/SQL Comments
• The PL/SQL supports single-line and multi-line comments.
• All characters available inside any comment are ignored by the PL/SQL compiler.
• The PL/SQL single-line comments start with the delimiter -- (double hyphen) and multi-line comments are enclosed by /*
and */.
Syntax Using -- symbol
The syntax for creating a SQL comment in Oracle using -- symbol is:
Syntax Using /* and */ symbols
The syntax for creating a SQL comment in Oracle using /* and */ symbols is:
Example - Comment on Multiple Lines
PL/SQL has two kinds of data types: scalar and composite. The scalar types are types that store single values
such as number, Boolean, character, and datetime whereas the composite types are types that store multiple
values, for example array, record and collection.
PL/SQL Data types
S.No Category & Description
1
Scalar
Single values with no internal components, such as a NUMBER,
DATE, or BOOLEAN.
2
Large Object (LOB)
Pointers to large objects that are stored separately from other data items,
such as text, graphic images, video clips, and sound waveforms.
3
Composite
Data items that have internal components that can be accessed
individually. For example, collections and records.
4
Reference
Pointers to other data items.
PL/SQL Scalar Data Types and Subtypes
S.No Date Type & Description
1
Numeric
Numeric values on which arithmetic operations are performed.
2
Character
Alphanumeric values that represent single characters or strings of
characters.
3
Boolean
Logical values on which logical operations are performed.
4
Datetime
Dates and times.
PL/SQL Scalar Data Types and Subtypes
PL/SQL Variables
A variable is a meaningful name which facilitates a programmer to store data temporarily during the execution of
code. It helps you to manipulate data in PL/SQL programs. It is nothing except a name given to a storage area. Each
variable in the PL/SQL has a specific data type which defines the size and layout of the variable's memory.
The syntax for a variable declaration is as follows:
variable_name datatype [NOT NULL] [:= initial_value];
Naming rules for PL/SQL variables
• The variable in PL/SQL must follow some naming rules like other programming languages.
• The variable_name should not exceed 30 characters.
• The name of the variable must begin with ASCII letter. The PL/SQL is not case sensitive so it could be either
lowercase or uppercase. For example: v_data and V_DATA refer to the same variables.
• You should make your variable easy to read and understand, after the first character, it may be any number,
underscore (_) or dollar sign ($).
DECLARE
a integer := 30;
b integer := 40;
c integer;
f real;
BEGIN
c := a + b;
dbms_output.put_line('Value of c: ' || c);
f := 100.0/3.0;
dbms_output.put_line('Value of f: ' || f);
END;
After the execution, this will produce the following result:
Value of c: 70
Value of f: 33.333333333333333333
PL/SQL procedure successfully completed.
Example of initializing variable
DECLARE
-- Global variables
num1 number := 95;
num2 number := 85;
BEGIN
dbms_output.put_line('Outer Variable num1: ' || num1);
dbms_output.put_line('Outer Variable num2: ' || num2);
DECLARE
-- Local variables
num1 number := 195;
num2 number := 185;
BEGIN
dbms_output.put_line('Inner Variable num1: ' || num1);
dbms_output.put_line('Inner Variable num2: ' || num2);
END;
END;
/
After the execution, this will produce the following result:
Outer Variable num1: 95
Outer Variable num2: 85
Inner Variable num1: 195
Inner Variable num2: 185
PL/SQL procedure successfully completed.
PL/SQL Constants
A constant is a value used in a PL/SQL block that remains unchanged throughout the program. It is a user-
defined literal value. It can be declared and used instead of actual values.
Suppose, you have to write a program which will increase the salary of the employees upto 30%, you can declare
a constant and use it throughout the program. Next time if you want to increase the salary again you can change
the value of constant than the actual value throughout the program.
Syntax to declare a constant:
constant_name CONSTANT datatype := VALUE;
Constant_name:it is the name of constant just like variable name. The constant word is a reserved
word and its value does not change.
VALUE: it is a value which is assigned to a constant when it is declared. It can not be assigned later.
DECLARE
-- constant declaration
pi constant number := 3.141592654;
-- other declarations
radius number(5,2);
dia number(5,2);
circumference number(7, 2);
area number (10, 2);
BEGIN
-- processing
radius := 9.5;
dia := radius * 2;
circumference := 2.0 * pi * radius;
area := pi * radius * radius;
-- output
dbms_output.put_line('Radius: ' || radius);
dbms_output.put_line('Diameter: ' || dia);
dbms_output.put_line('Circumference: ' || circumference);
dbms_output.put_line('Area: ' || area);
END;
/
After the execution of the above code at SQL prompt, it will produce the following result:.
Radius: 9.5
Diameter: 19
Circumference: 59.69
Area: 283.53
Pl/SQL procedure successfully completed.
Literals Examples
Numeric 75125, 3568, 33.3333333 etc.
Character 'A' '%' '9' ' ' 'z' '('
String Hello JavaTpoint!
Boolean TRUE, FALSE, NULL etc.
Date and Time '26-11-2002' , '2012-10-29 12:01:01'
PL/SQL Literals
Literals are the explicit numeric, character, string or boolean values which are not represented by an
identifier. For example: TRUE, NULL, etc. are all literals of type boolean. PL/SQL literals are case-
sensitive. There are following kinds of literals in PL/SQL:
•Numeric Literals
•Character Literals
•String Literals
•BOOLEAN Literals
•Date and Time Literals

More Related Content

PDF
Oracle PL/SQL online training | PL/SQL online Training
PPTX
Introduction to PL/SQL
PPT
10g plsql slide
PPT
Plsql overview
PPT
Chapter8 pl sql
PDF
PL/SQL Complete Tutorial. All Topics Covered
PPT
ORACLE PL SQL
PDF
SQL Complete Tutorial. All Topics Covered
Oracle PL/SQL online training | PL/SQL online Training
Introduction to PL/SQL
10g plsql slide
Plsql overview
Chapter8 pl sql
PL/SQL Complete Tutorial. All Topics Covered
ORACLE PL SQL
SQL Complete Tutorial. All Topics Covered

What's hot (19)

PPTX
pl/sql online Training|sql online Training | iTeknowledge
DOC
3963066 pl-sql-notes-only
PDF
PL-SQL, Cursors & Triggers
PPTX
4. plsql
PPTX
PL/SQL Fundamentals I
PDF
Oracle sql & plsql
PPT
PDF
PPTX
Packages in PL/SQL
PPTX
Oracle: PLSQL Introduction
PDF
Oracle db subprograms
PPT
1 - Introduction to PL/SQL
PPTX
Unit1
PPTX
Pl sql chapter 1
PDF
Pl sql-ch1
ODP
Open Gurukul Language PL/SQL
PPT
Oracle PLSQL Step By Step Guide
PDF
Pl sql-ch2
PPTX
PLSQL Tutorial
pl/sql online Training|sql online Training | iTeknowledge
3963066 pl-sql-notes-only
PL-SQL, Cursors & Triggers
4. plsql
PL/SQL Fundamentals I
Oracle sql & plsql
Packages in PL/SQL
Oracle: PLSQL Introduction
Oracle db subprograms
1 - Introduction to PL/SQL
Unit1
Pl sql chapter 1
Pl sql-ch1
Open Gurukul Language PL/SQL
Oracle PLSQL Step By Step Guide
Pl sql-ch2
PLSQL Tutorial
Ad

Similar to Pl sql content (20)

PDF
Dbmsunit v
PDF
Oracle Introduction
PDF
Database Systems - Introduction to SQL (Chapter 3/1)
PPTX
SQL Training courses.pptx
PPTX
Data Manipulation ppt. for BSIT students
PPTX
Data Analytics - SQL Lesson 01 - Introduction.pptx
DOCX
Database management system
PPTX
Dbms and sqlpptx
PPT
Database
PDF
csedatabasemanagementsystemppt-170825044344.pdf
PPTX
Database Management System ppt
DOCX
Dbms notes
PPT
Unit01 dbms
PPTX
PPTX
structures query langauge basic for learners
PPTX
Introduction to Database Management Systems and SQL
PDF
SQL EXCLUSIVE NOTES .pdf
PPTX
Introduction to SQL, SQL*Plus
PPTX
Intro sql/plsql
PPTX
Ch 2-introduction to dbms
Dbmsunit v
Oracle Introduction
Database Systems - Introduction to SQL (Chapter 3/1)
SQL Training courses.pptx
Data Manipulation ppt. for BSIT students
Data Analytics - SQL Lesson 01 - Introduction.pptx
Database management system
Dbms and sqlpptx
Database
csedatabasemanagementsystemppt-170825044344.pdf
Database Management System ppt
Dbms notes
Unit01 dbms
structures query langauge basic for learners
Introduction to Database Management Systems and SQL
SQL EXCLUSIVE NOTES .pdf
Introduction to SQL, SQL*Plus
Intro sql/plsql
Ch 2-introduction to dbms
Ad

Recently uploaded (20)

PPTX
The spiral of silence is a theory in communication and political science that...
PPTX
Tablets And Capsule Preformulation Of Paracetamol
DOC
学位双硕士UTAS毕业证,墨尔本理工学院毕业证留学硕士毕业证
PPTX
ART-APP-REPORT-FINctrwxsg f fuy L-na.pptx
PPTX
PHIL.-ASTRONOMY-AND-NAVIGATION of ..pptx
PPTX
Presentation for DGJV QMS (PQP)_12.03.2025.pptx
PDF
oil_refinery_presentation_v1 sllfmfls.pdf
DOCX
ENGLISH PROJECT FOR BINOD BIHARI MAHTO KOYLANCHAL UNIVERSITY
PPTX
BIOLOGY TISSUE PPT CLASS 9 PROJECT PUBLIC
PPTX
Primary and secondary sources, and history
PPTX
Relationship Management Presentation In Banking.pptx
PPTX
Introduction to Effective Communication.pptx
PPT
The Effect of Human Resource Management Practice on Organizational Performanc...
PPTX
Self management and self evaluation presentation
PPTX
AcademyNaturalLanguageProcessing-EN-ILT-M02-Introduction.pptx
PPTX
Human Mind & its character Characteristics
PDF
Instagram's Product Secrets Unveiled with this PPT
PPTX
lesson6-211001025531lesson plan ppt.pptx
PPTX
Role and Responsibilities of Bangladesh Coast Guard Base, Mongla Challenges
PPTX
Effective_Handling_Information_Presentation.pptx
The spiral of silence is a theory in communication and political science that...
Tablets And Capsule Preformulation Of Paracetamol
学位双硕士UTAS毕业证,墨尔本理工学院毕业证留学硕士毕业证
ART-APP-REPORT-FINctrwxsg f fuy L-na.pptx
PHIL.-ASTRONOMY-AND-NAVIGATION of ..pptx
Presentation for DGJV QMS (PQP)_12.03.2025.pptx
oil_refinery_presentation_v1 sllfmfls.pdf
ENGLISH PROJECT FOR BINOD BIHARI MAHTO KOYLANCHAL UNIVERSITY
BIOLOGY TISSUE PPT CLASS 9 PROJECT PUBLIC
Primary and secondary sources, and history
Relationship Management Presentation In Banking.pptx
Introduction to Effective Communication.pptx
The Effect of Human Resource Management Practice on Organizational Performanc...
Self management and self evaluation presentation
AcademyNaturalLanguageProcessing-EN-ILT-M02-Introduction.pptx
Human Mind & its character Characteristics
Instagram's Product Secrets Unveiled with this PPT
lesson6-211001025531lesson plan ppt.pptx
Role and Responsibilities of Bangladesh Coast Guard Base, Mongla Challenges
Effective_Handling_Information_Presentation.pptx

Pl sql content

  • 2. Content • PL/SQL Introduction • What is Data • What is information • Database • Database of management studies • Application of DBMS • Types of DBMS • SQL • SQL Command • Sample SQL creating table
  • 3. PL/SQL stands for “Procedural Language extensions to the structured query Language”. SQL is a popular language for both querying and updating data in the relational database management systems (RDBMS). PL/SQL adds many procedural constructs to SQL language to overcome some limitations of SQL. PL/SQL One can create a PL/SQL unit such as procedures, functions, packages, triggers, and types, which are stored in the database for reuse by applications.
  • 4. What is Data • A collection of raw facts and figures • Raw Material that can be processed by computing machine • A collection of facts from which conclusions may be drawn • Data can be represented in the form of numbers and words which can be stored in computer’s language
  • 5. What is information • Systematic and meaningful form of data • Knowledge acquired through study or experience • Information helps human beings in their decision making
  • 6. Database • A repository of logically related and similar data • An organized collection of related information so that it can easily be accessed, managed and updated Eg: • Dictionary • Airline Database • Student Database • Library • Railways Timetable • YouTube(All Songs of Rahul Vaidya)
  • 7. What is DBMS • DBMS stands for Database Management System • DBMS is a software system for creating , organizing and managing the database • It provides an environment to the user to perform operations on the database for creation, insertion, deletion, updating and retrieval of data
  • 8. Why Use a DBMS • Data independence and efficient access • Reduced application development time • Data integrity and security • Uniform data administration • Concurrent access, recovery from crashes.
  • 9. DifferentpeoplebehindDBMS • Database Administrator(DBA)- The DBA is responsible for authorizing access to the database, for coordinating and monitoring its use, an for acquiring software and hardware resources as need • Database Designers - Database designers are responsible for identifying the data to be stored in the database or choosing appropriate structures to represent and store this data. These tasks are mostly undertaken before the database is actually implemented and populated with data • End Users – • Casual end users, • naïve or parametric end users, • Sophisticated end users, • stand-alone users • System Analysts and Application Programmers – Application programmers implement these specifications as programs, then they test, debug, document, and maintain theses canned transactions • DBMS Designers and implementers : are persons who design and implement the DBMS modules and interfaces as a software package. • Tool Developers : They include package for database design, performance monitoring, natural language or graphical interfaces, prototyping ,simulation , and test data generation • Operators and Maintenance Personnel : are the system administration personnel who are responsible for the actual running and maintenance of the hardware and software environment for the database system
  • 10. Application of DBMS Sector Use of DBMS Banking For customer information, account activities, payments, deposits, loans, etc. Airlines For reservations and schedule information. Universities For student information, course registrations, colleges and grades. Telecommunication It helps to keep call records, monthly bills, maintaining balances, etc. Finance For storing information about stock, sales, and purchases of financial instruments like stocks and bonds. Sales Use for storing customer, product & sales information. Manufacturing It is used for the management of supply chain and for tracking production of items. Inventories status in warehouses. HR Management For information about employees, salaries, payroll, deduction, generation of paychecks, etc.
  • 11. Types of DBMS Hierarchical DBMS In a Hierarchical database, model data is organized in a tree-like structure. Data is Stored Hierarchically (top down or bottom up) format. Data is represented using a parent-child relationship. In Hierarchical DBMS parent may have many children, but children have only one parent. Network Model The network database model allows each child to have multiple parents. It helps you to address the need to model more complex relationships like as the orders/parts many-to-many relationship. In this model, entities are organized in a graph which can be accessed through several paths. Relational model Relational DBMS is the most widely used DBMS model because it is one of the easiest. This model is based on normalizing data in the rows and columns of the tables. Relational model stored in fixed structures and manipulated using SQL. Object-Oriented Model In Object-oriented Model data stored in the form of objects. The structure which is called classes which display data within it. It defines a database as a collection of objects which stores both data members values and operations.
  • 12. What is SQL SQL is used to communicate with a database. According to ANSI (American National Standards Institute), it is the standard language for relational database management systems. SQL statements are used to perform tasks such as update data on a database, or retrieve data from a database.
  • 13. Fact of SQL SQL was developed at IBM by Donald D. Chamberlin and Raymond F Boyce in the early 1970s It was initially called SEQUEL(Structured English Query Language) SQL is a powerful language that uses simple English sentences SQL is a Declarative Language
  • 14. • Structure Query Language(SQL) is a database query language used for storing and managing data in Relational DBMS. • 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.
  • 15. SQL Command DDL: Data Definition Language Data Definition Language (DDL) statement are used to define the database structure or schema Some example CREATE- to create objects in the database ALTER- alters the structure of the database DROP- delete objects from the database TRUNCATE- remove all records from a table, including all space allocated for the records are removed COMMENT – add comments to the data dictionary RENAME-rename an object
  • 16. DML: Data Manipulation Language Data Manipulation Language(DML) statement are used for managing data within schema objects SELECT- Retrieve data from the a database INSERT- Insert data into a table UPDATE- Updates existing data within a table DELETE - deletes all records from a table, the space for the records remain
  • 17. • TCL: Transaction Control Language (These commands are to keep a check on other commands and their affect on the database.(commit, rollback) • DCL: Data Control Language(grant: permission) • DQL: Data Query Language (select)
  • 18. create table students(regno number(10), name varchar2(15), major varchar2(8)); desc students; insert into students values('03','naveen','maths') insert into students values('04','naveen','maths') insert into students values('05','naveen','maths') select * from students Select regno ,major from students delete students alter table studentss rename to stud; drop table stud; desc stud; Sample SQL creating table
  • 19. SQL and PL/SQL execution STEP-01
  • 30. Exercise-01 1.Write a SQL statement to display all the information of all salesmen. Sample table: salesman
  • 31. Exercise-01- Solution 1.Write a SQL statement to display all the information of all salesmen. Sample table: salesman create table salesmen(sales_id number(10), name varchar(12), city varchar(10), commission number(20)); insert into salesmen values(500,'james Hoog','New york',0.15);
  • 33. Solution create table Worker1(worker_id number(10),firstname char(23),lastname char(23),salary number(15),department char(24)); insert into Worker1 values (001, 'Monika', 'Arora', 100000,'HR'); select * from Worker1;
  • 34. Disadvantages of SQL • SQL doesn’t provide the programmers with a technique of condition checking, looping and branching. • SQL statements are passed to Oracle engine one at a time which increases traffic and decreases speed. • SQL has no facility of error checking during manipulation of data. • For SQL need training to an excess database. • SQL can be handled by an expert user or programmer. • It occupies some space i.e extra memory location for each record. • It is a command based language. • It is platform dependent language.
  • 35. Introduction to PL/SQL PL/SQL stands for “Procedural Language extensions to the structured Query Language A procedural language is a type of computer programming language that specifies a series of well-structured steps and procedures within its programming context to compose a program. It contains a systematic order of statements, functions and commands to complete a computational task or program. The PL/SQL programming language was developed by Oracle Corporation in the late 1980s as procedural extension language for SQL and the Oracle relational database. Following are certain notable facts about PL/SQL − • PL/SQL is a completely portable, high-performance transaction-processing language. • PL/SQL provides a built-in, interpreted and OS independent programming environment. • PL/SQL can also directly be called from the command-line SQL*Plus interface. • Direct call can also be made from external programming language calls to database. • PL/SQL's general syntax is based on that of ADA and Pascal programming language. • Apart from Oracle, PL/SQL is available in TimesTen in-memory database and IBM DB2.
  • 36. Features of PL/SQL Portable: PL/SQL applications can be executed with all types of operating system where we have oracle installed. Efficient: All sorts of calculations can be efficiently performed by PL/SQL without the use of oracle engine. This improves transaction performance. Error-checking PL/SQL allows error-checking and displays user-friendly messages when error occurs. Development tool: PL/SQL supports execution of SQL statements along with the functionality of variable declaration, conditional statements, looping and branching, procedures, functions and triggers. Exception Handling: PL/SQL code is capable of handling exceptions that can affect the flow of program, hence helps in making the code more reliable
  • 37. • For example, consider we have a School Management System database and we want to see the list of students who took admission in last 5 years in school and the fees deposited by them. • And at the same time we want to add the total amount of salary money given to the teaching and non-teaching staff. We cannot fetch these records by just executing SQL queries, we might be able to gather the data but it would require multiple SQL queries. • On the other hand if we use PL/SQL, we can write procedures or methods in PL/SQL program to execute complex logic on a database. • Another advantage is that we can also detect errors easily as it displays user- friendly messages and it even supports exception handling.
  • 38. SQL PL/SQL SQL is a single query that is used to perform DML and DDL operations. PL/SQL is a block of codes that used to write the entire program blocks/ procedure/ function, etc. It is declarative, that defines what needs to be done, rather than how things need to be done. PL/SQL is procedural that defines how the things needs to be done. Execute as a single statement. Execute as a whole block. Mainly used to manipulate data. Mainly used to create an application. Cannot contain PL/SQL code in it. It is an extension of SQL, so it can contain SQL inside it. Differences between SQL and PL/SQL:
  • 42. Architecture of PL/SQL The PL/SQL architecture mainly consists of following three components: – PL/SQL block – PL/SQL Engine – Database Server PL/SQL block This is the component which has the actual PL/SQL code. This consists of different sections to divide the code logically (declarative section for declaring purpose, execution section for processing statements, exception handling section for handling errors) It also contains the SQL instruction that used to interact with the database server. All the PL/SQL units are treated as PL/SQL blocks, and this is the starting stage of the architecture which serves as the primary input
  • 43. Following are the different type of PL/SQL units. Anonymous Block Function Library Procedure Package Body Package Specification Trigger Type Type Body
  • 44. PL/SQL Engine • PL/SQL engine is the component where the actual processing of the codes takes place. • PL/SQL engine separates PL/SQL units and SQL part in the input. • The separated PL/SQL units will be handled by the PL/SQL engine itself. • The SQL part will be sent to database server where the actual interaction with database takes place. • It can be installed in both database server and in the application server
  • 45. Database Server: • This is the most important component of Pl/SQL unit which stores the data. • The PL/SQL engine uses the SQL from PL/SQL units to interact with the database server. • It consists of SQL executor which parses the input SQL statements and execute the same.
  • 46. Typically, each block performs a logical action in the program. A block has the following structure:
  • 47. DECLARE • Declare section starts with DECLARE keyword in which variables, constants, records as cursors can be declared which stores data temporarily. It basically consists definition of PL/SQL identifiers. This part of the code is optional. EXECUTION SECTION • Execution section starts with BEGIN and ends with END keyword. • This is a mandatory section and here the program logic is written to perform any task like loops and conditional statements. • It should have at least one executable line of code, which may be just a NULL command to indicate that nothing should be executed. EXCEPTION • Exception section starts with EXCEPTION keyword. • This section is optional which contains statements that are executed when a run-time error occurs. • Any exceptions can be handled in this section.
  • 48. PL/SQL SET Serveroutput ON • Whenever you start Oracle SQL (PL/SQL) at that time you must have to write the "SET Serveroutput ON" command. • PL/SQL program execution into Oracle engine so we always required to get serveroutput result and display into the screen otherwise result can't be display.
  • 49. PL/SQL anonymous block example • The following example shows a simple PL/SQL anonymous block with one executable section. To run the code from the SQL command line, you may need to type / at the beginning of the first blank line after the last line of the code. When the above code is executed at the SQL prompt, it produces the following result − Hello There PL/SQL procedure successfully completed.
  • 50. The 'Hello World' Example
  • 51. The PL/SQL Comments • The PL/SQL supports single-line and multi-line comments. • All characters available inside any comment are ignored by the PL/SQL compiler. • The PL/SQL single-line comments start with the delimiter -- (double hyphen) and multi-line comments are enclosed by /* and */. Syntax Using -- symbol The syntax for creating a SQL comment in Oracle using -- symbol is: Syntax Using /* and */ symbols The syntax for creating a SQL comment in Oracle using /* and */ symbols is:
  • 52. Example - Comment on Multiple Lines
  • 53. PL/SQL has two kinds of data types: scalar and composite. The scalar types are types that store single values such as number, Boolean, character, and datetime whereas the composite types are types that store multiple values, for example array, record and collection. PL/SQL Data types S.No Category & Description 1 Scalar Single values with no internal components, such as a NUMBER, DATE, or BOOLEAN. 2 Large Object (LOB) Pointers to large objects that are stored separately from other data items, such as text, graphic images, video clips, and sound waveforms. 3 Composite Data items that have internal components that can be accessed individually. For example, collections and records. 4 Reference Pointers to other data items. PL/SQL Scalar Data Types and Subtypes
  • 54. S.No Date Type & Description 1 Numeric Numeric values on which arithmetic operations are performed. 2 Character Alphanumeric values that represent single characters or strings of characters. 3 Boolean Logical values on which logical operations are performed. 4 Datetime Dates and times. PL/SQL Scalar Data Types and Subtypes
  • 55. PL/SQL Variables A variable is a meaningful name which facilitates a programmer to store data temporarily during the execution of code. It helps you to manipulate data in PL/SQL programs. It is nothing except a name given to a storage area. Each variable in the PL/SQL has a specific data type which defines the size and layout of the variable's memory. The syntax for a variable declaration is as follows: variable_name datatype [NOT NULL] [:= initial_value]; Naming rules for PL/SQL variables • The variable in PL/SQL must follow some naming rules like other programming languages. • The variable_name should not exceed 30 characters. • The name of the variable must begin with ASCII letter. The PL/SQL is not case sensitive so it could be either lowercase or uppercase. For example: v_data and V_DATA refer to the same variables. • You should make your variable easy to read and understand, after the first character, it may be any number, underscore (_) or dollar sign ($).
  • 56. DECLARE a integer := 30; b integer := 40; c integer; f real; BEGIN c := a + b; dbms_output.put_line('Value of c: ' || c); f := 100.0/3.0; dbms_output.put_line('Value of f: ' || f); END; After the execution, this will produce the following result: Value of c: 70 Value of f: 33.333333333333333333 PL/SQL procedure successfully completed. Example of initializing variable
  • 57. DECLARE -- Global variables num1 number := 95; num2 number := 85; BEGIN dbms_output.put_line('Outer Variable num1: ' || num1); dbms_output.put_line('Outer Variable num2: ' || num2); DECLARE -- Local variables num1 number := 195; num2 number := 185; BEGIN dbms_output.put_line('Inner Variable num1: ' || num1); dbms_output.put_line('Inner Variable num2: ' || num2); END; END; / After the execution, this will produce the following result: Outer Variable num1: 95 Outer Variable num2: 85 Inner Variable num1: 195 Inner Variable num2: 185 PL/SQL procedure successfully completed.
  • 58. PL/SQL Constants A constant is a value used in a PL/SQL block that remains unchanged throughout the program. It is a user- defined literal value. It can be declared and used instead of actual values. Suppose, you have to write a program which will increase the salary of the employees upto 30%, you can declare a constant and use it throughout the program. Next time if you want to increase the salary again you can change the value of constant than the actual value throughout the program. Syntax to declare a constant: constant_name CONSTANT datatype := VALUE; Constant_name:it is the name of constant just like variable name. The constant word is a reserved word and its value does not change. VALUE: it is a value which is assigned to a constant when it is declared. It can not be assigned later.
  • 59. DECLARE -- constant declaration pi constant number := 3.141592654; -- other declarations radius number(5,2); dia number(5,2); circumference number(7, 2); area number (10, 2); BEGIN -- processing radius := 9.5; dia := radius * 2; circumference := 2.0 * pi * radius; area := pi * radius * radius; -- output dbms_output.put_line('Radius: ' || radius); dbms_output.put_line('Diameter: ' || dia); dbms_output.put_line('Circumference: ' || circumference); dbms_output.put_line('Area: ' || area); END; / After the execution of the above code at SQL prompt, it will produce the following result:. Radius: 9.5 Diameter: 19 Circumference: 59.69 Area: 283.53 Pl/SQL procedure successfully completed.
  • 60. Literals Examples Numeric 75125, 3568, 33.3333333 etc. Character 'A' '%' '9' ' ' 'z' '(' String Hello JavaTpoint! Boolean TRUE, FALSE, NULL etc. Date and Time '26-11-2002' , '2012-10-29 12:01:01' PL/SQL Literals Literals are the explicit numeric, character, string or boolean values which are not represented by an identifier. For example: TRUE, NULL, etc. are all literals of type boolean. PL/SQL literals are case- sensitive. There are following kinds of literals in PL/SQL: •Numeric Literals •Character Literals •String Literals •BOOLEAN Literals •Date and Time Literals