Description:
Welcome to the comprehensive guide on Relational Database Management System (RDBMS) concepts, tailored for final year B.Sc. Computer Science students affiliated with Alagappa University. This document covers fundamental principles and advanced topics in RDBMS, offering a structured approach to understanding databases in the context of modern computing. PDF content is prepared from the text book Learn Oracle 8I by JOSE A RAMALHO.
Key Topics Covered:
Main Topic : PL/SQL
Sub-Topic :
Structure of PL/SQL Block, Declaration Section, Variable, Constant, Execution Section, Exception, How PL/SQL works, Control Structures, If then Command,
Loop Command, Loop with IF, Loop with When, For Loop Command, While Command, Integrating SQL in PL/SQL program.
Target Audience:
Final year B.Sc. Computer Science students at Alagappa University seeking a solid foundation in RDBMS principles for academic and practical applications.
URL for previous slides
Unit V
Chapter 15
Unit IV
Chapter 14 Synonym : https://www.slideshare.net/slideshow/lecture_notes_unit4_chapter14_synonyms-pdf/270327685
Chapter 13 Users, Privileges : https://www.slideshare.net/slideshow/lecture-notes-unit4-chapter13-users-roles-and-privileges/270304806
Chapter 12 View : https://www.slideshare.net/slideshow/rdbms-lecture-notes-unit4-chapter12-view/270199683
Chapter 11 Sequence: https://www.slideshare.net/slideshow/sequnces-lecture_notes_unit4_chapter11_sequence/270134792
chapter 8,9 and 10 : https://www.slideshare.net/slideshow/lecture_notes_unit4_chapter_8_9_10_rdbms-for-the-students-affiliated-by-alagappa-university/270123800
About the Author:
Dr. S. Murugan is Associate Professor at Alagappa Government Arts College, Karaikudi. With 23 years of teaching experience in the field of Computer Science, Dr. S. Murugan has a passion for simplifying complex concepts in database management.
Disclaimer:
This document is intended for educational purposes only. The content presented here reflects the author’s understanding in the field of RDBMS as of 2024.
The document provides an overview of PL/SQL programming concepts including:
1. PL/SQL blocks can contain declaration, executable, and exception handling sections.
2. Variables can be declared and assigned values using PL/SQL expressions.
3. SQL statements like INSERT, UPDATE, DELETE and SELECT can be used within PL/SQL blocks to manipulate database data.
The document provides an overview of PL/SQL and server-side database programming. It discusses:
1) What PL/SQL is and how it extends SQL with programming features like variables, loops, and conditionals to allow for procedural logic on the server-side.
2) The advantages of server-side programming using PL/SQL over client-side programming, including improved performance due to reduced network traffic and ability to reuse code.
3) Key PL/SQL concepts like blocks, data types, scope rules, operators, program flow control structures, exceptions, and subprograms like procedures and functions.
The document discusses functions and stored procedures in SQL. Functions are logical grouped SQL/PL statements that perform a specific task and return a value, while stored procedures perform a specific task without returning a value. The document provides examples of creating simple SQL functions that return values and a stored procedure that updates employee salaries and bonuses.
The document discusses functions and stored procedures in SQL. Functions are logical grouped SQL/PL statements that perform a specific task and return a value, while stored procedures perform a specific task without returning a value. The document provides examples of creating simple SQL functions that return values and a stored procedure that updates employee salaries and bonuses.
PL/SQL is a combination of SQL and procedural programming languages. It allows developers to perform operations like control flow statements, variable declarations, and exception handling. PL/SQL code is organized into blocks that contain a declarative part, an executable part, and an optional exception-handling part. Variables and other objects can be declared locally or globally depending on their scope. Control structures like IF-THEN-ELSE, CASE, and loops allow conditional and iterative execution. Procedures and functions can also be created to reuse code.
This document provides an introduction and overview of stored procedures and functions in SQL. It discusses transaction management using COMMIT and ROLLBACK statements. It defines stored procedures as precompiled collections of SQL statements that can accept parameters and return values. Stored procedures offer benefits like modular programming and faster execution. The document also introduces user-defined functions and provides examples of creating and executing stored procedures and functions.
What is PL/SQL
Procedural Language – SQL
An extension to SQL with design features of programming languages (procedural and object oriented)
PL/SQL and Java are both supported as internal host languages within Oracle products.
Functions allow structuring the programs in segments of code to perform individual tasks. The typical case for creating a function is when one needs to perform the same action multiple times in a program.
Standardizing code fragments into functions has several advantages −
Functions help the programmer stay organized. Often this helps to conceptualize the program.
Functions codify one action in one place so that the function only has to be thought about and debugged once.
This also reduces chances for errors in modification, if the code needs to be changed.
Functions make the whole sketch smaller and more compact because sections of code are reused many times.
They make it easier to reuse code in other programs by making it modular, and using functions often makes the code more readable.
This document discusses embedded SQL, functions, procedures, and triggers. Embedded SQL allows SQL statements to be embedded within host languages like C/C++ and Java. Functions and procedures can be written in SQL or an external language and used to perform calculations on data. Triggers are stored programs that automatically execute in response to data changes or other events. The document provides examples of how to create and use these database objects to query and manipulate data.
PL/SQL provides two types of composite datatypes - records and collections. Records allow grouping of related data elements, while collections allow storing multiple values in a single variable. Collections include index-by tables, nested tables, and varrays. Cursors allow processing rows from a SQL query one by one. Explicit cursors must be declared, opened, fetched from, and closed. Implicit cursors are used for DML statements. Functions return a value and can be used in SQL expressions, while procedures perform actions without returning a value. Both can accept parameters.
A stored procedure is a subroutine stored in a database that can be called to perform a specific task. Stored procedures consolidate and centralize logic that was originally implemented across multiple applications. They improve performance by only sending the procedure name and parameters rather than multiple SQL statements. Stored procedures also increase security by allowing access permissions to be set at the procedure level. Common uses include data validation and access control mechanisms integrated into the database.
A stored procedure is a subroutine available to applications that access a relational database. Extensive or complex SQL processing is moved into stored procedures to improve performance. Stored procedures offer advantages like improved security, reduced network traffic, and easier maintenance compared to embedding SQL statements in an application. They allow parameters to be passed in and support flow control structures like IF/THEN clauses.
This document provides information on PL/SQL programming language concepts including:
- PL/SQL allows defining logic using variables, conditional statements, loops, and object-oriented programming.
- Code is organized into blocks with declaration, executable, and exception sections.
- Variables can be declared and assigned values. Data types include numbers, strings, records, and collections.
- Conditional statements like IF-THEN-ELSE and CASE support different execution paths.
- Loops like simple, while, and for are used to iterate.
- Cursors access and process multiple database records in PL/SQL blocks.
This document provides information on PL/SQL programming language concepts. Some key points:
- PL/SQL allows defining logic blocks that can execute SQL and PL/SQL statements. Blocks have optional declaration, executable, and exception sections.
- PL/SQL supports variables, conditional statements like IF/CASE, and looping with LOOP/WHILE/FOR. Variables can be bound to table columns using %TYPE.
- Cursors allow processing multiple database records in PL/SQL. Explicit cursors are declared and opened/fetched/closed manually while implicit cursors are used for single record queries.
- Parameter cursors can accept parameters. Nested cursors allow querying related data. Cursors
PL/SQL is an extension of SQL that allows procedural logic to be added to SQL statements and queries. Key features of PL/SQL include blocks, exceptions, cursors, procedures, functions, packages, and triggers. A PL/SQL block contains a declare section to define variables, an executable section to contain program logic, and an optional exception section. Exceptions can be predefined, non-predefined, or user-defined. The document provides examples of handling different types of exceptions within PL/SQL blocks to avoid abnormal program termination.
MySQL is an open-source relational database management system that uses SQL and runs a server providing multi-user access to databases. It allows users to perform queries and make changes to data through commands like SELECT, INSERT, UPDATE, DELETE. Stored procedures and functions allow users to write and save blocks of SQL code for repeated execution with consistent results.
PL/SQL is a programming language and control structures used for Oracle databases. It allows for procedural programming, object-oriented programming features like data encapsulation and error handling. PL/SQL code is organized into logical blocks like anonymous and named blocks. It supports various data types, variables, control structures like conditional statements and loops, and SQL statements for data manipulation.
Similar to Lecture Notes Unit5 chapter 15 PL/SQL Programming (20)
Odoo 17 Project Module : New Features - Odoo 17 SlidesCeline George
The Project Management module undergoes significant enhancements, aimed at providing users with more robust tools for planning, organizing, and executing projects effectively.
Introduction to Literary Criticism 10 (1).pptxjessintv
Introduction to Literary Criticism prepared by Mrs.V.Jesinthal Mary,Asst.Professor,Dept of English and other foreign Languages (EFL), SRMIST Science and Humanities, Ramapuram,
Chennai-600089
How to Use Serial Numbers to Track Products in Odoo 17 InventoryCeline George
Mainly lots or serial numbers are used for tracking the products. Lots are actually the codes that applied for collection of products. But serial numbers are distinct numbers allocated for a particular product. Lots and serial numbers in the products will help to manage the inventory, to trace the products that reached their expiry date. This slide will show how to use lots and serial numbers to track products in odoo 17 inventory.
How to Add Collaborators to a Project in Odoo 17Celine George
Effective project management in Odoo 17 hinges on collaboration. By adding collaborators, we can assign tasks, share information, and keep everyone on the same page.
Plato and Aristotle's Views on Poetry by V.Jesinthal Maryjessintv
PPT on Plato and Aristotle's Views on Poetry prepared by Mrs.V.Jesinthal Mary, Dept of English and Foreign Languages(EFL),SRMIST Science and Humanities ,Ramapuram,Chennai-600089
Types of Diode and its working principle.pptxnitugatkal
A diode is a two-terminal polarized electronic component which mainly conducts current in one direction and blocks in other direction.
Its resistance in one direction is low (ideally zero) and high (ideally infinite) resistance in the other direction.
How to install python packages from PycharmCeline George
In this slide, let's discuss how to install Python packages from PyCharm. In case we do any customization in our Odoo environment, sometimes it will be necessary to install some additional Python packages. Let’s check how we can do this from PyCharm.
Tale of a Scholar and a Boatman ~ A Story with Life Lessons (Eng. & Chi.).pptxOH TEIK BIN
A PowerPoint Presentation of a meaningful story that teaches important Life Lessons /Virtues /Moral values.
The texts are in English and Chinese.
For the Video with audio narration and explanation in English, please check out the Link:
https://www.youtube.com/watch?v=GH71Ds2WzU8
How to Use Quality Module in Odoo 17 - Odoo 17 SlidesCeline George
To improve the quality of our business we have to supervise all the operations and tasks. We can do different quality checks before the product is put to the market. We can do all these activities in a single module that is the Quality module in Odoo 17. This slide will show how to use the quality module in odoo 17.
Dear Sakthi Thiru Dr. G. B. Senthil Kumar,
It is with great honor and respect that we extend this formal invitation to you. As a distinguished leader whose presence commands admiration and reverence, we cordially invite you to join us in celebrating the 25th anniversary of our graduation from Adhiparasakthi Engineering College on 27th July, 2024. we would be honored to have you by our side as we reflect on the achievements and memories of the past 25 years.
How to Restrict Price Modification to Managers in Odoo 17 POSCeline George
This slide will represent the price control functionality in Odoo 17 PoS module. This feature provides the opportunity to restrict price adjustments. We can limit pricing changes to managers exclusively with it.
How to Configure Extra Steps During Checkout in Odoo 17 Website AppCeline George
Odoo websites allow us to add an extra step during the checkout process to collect additional information from customers. This can be useful for gathering details that aren't necessarily covered by standard shipping and billing addresses.
1. RDBMS - Unit V
Chapter 15
PL/SQL
Prepared By
Dr. S.Murugan, Associate Professor
Department of Computer Science,
Alagappa Government Arts College, Karaikudi.
(Affiliated by Alagappa University)
Mailid: muruganjit@gmail.com
Reference Book:
LEARN ORACLE 8i, JOSE A RAMALHO
2. PL/SQL
➢ PL/SQL is an extension of the SQL language.
➢ It is a procedural language.
➢ PL/SQL combines the SQL language’s ease of data
manipulation and the procedural language’s ease of
programming.
➢ With the PL/SQL language, we can create schema
objects, including Stored procedures and functions,
Packages, Triggers, Cursors.
3. PL/SQL
➢ Stored procedures and functions. A stored procedure
is a PL/SQL program that can be enabled by an
application, a trigger, or an Oracle tool.
➢ The basic difference between a procedure and a
function is that a procedure executes its commands
and a function executes commands and returns a
result.
➢ Packages. A package is a file that contains a group of
functions, cursors, stored procedures, and variables in
one place.
4. PL/SQL
➢ Triggers. A trigger is a PL/SQL program that is stored
in the database and executed immediately before or
after the INSERT, UPDATE, and DELETE
commands.
➢ Cursors. Oracle uses workspaces to execute the SQL
commands. Through PL/SQL cursors, it is possible to
name the workspace and access its information.
6. PL/SQL BLOCK
There are three parts to the PL/SQL block:
➢ Declaration section/Declare (optional), in which all
the objects are declared.
➢ Execution section/Begin, in which the PL/SQL
commands are placed.
➢ Exception section/Exception (optional), in which the
errors are handled.
7. PL/SQL BLOCK - Declaration Section
In the declaration section, the developer can perform the
following:
➢ Declare the name of an identifier - PI.
➢ Declare the type of identifier (constant or variable).
➢ Declare the data type of the identifier. - REAL
➢ Assign (initialize) contents to the identifier. – 3.14
Ex: PI CONSTANT REAL := 3.14
8. PL/SQL BLOCK - Variables
➢ The variables can contain any data type that is valid
for SQL and Oracle (such as char, number, long,
varchar2, and date) in addition to these types:
➢ Boolean Can be assigned the values True, False, or
NULL.
➢ Binary_integer Accepts numbers between
-2,147,483,647 and 2,147,483,647.
➢ Positive Accepts numbers from 1 to 2,147,483,647.
➢ Natural Accepts numbers from 0 to 2,147,483,647.
9. PL/SQL BLOCK - Variables
➢ %type Assigns to the variable that is being created the
same data types used by the column that is being used.
To access the field of deptno from dept. table and
assigned to deptp.
deptp := dept.deptno%type;
➢ %rowtype Declares a composed variable that is
equivalent to the row of the table.
➢ After the variable is created, the fields of the table can
be accessed, using the name of this variable followed
by a period and the name of the field:
Empline := emp%rowtype
10. PL/SQL BLOCK - Variables
➢ After the variable is created, you can use the following
expression to assign a column to another variable:
Newvar : = empline.ename;
11. PL/SQL BLOCK - Variables
➢ There are two ways to assign values to a variable. The
first is to use the assignment operator “:=”:
tot := price * margin;
increase:= sal * 1.10;
➢ The second way to assign values to variables is to use
the SELECT command to assign the contents of the
fields of a table to a variable:
SELECT sal * 0.10 INTO increased FROM
emp WHERE empno = emp_id;
12. PL/SQL BLOCK - Constant
➢ The declaration of a constant is similar to the
declaration of a variable, except to add the keyword
Constant after the name of the constant:
PI CONSTANT REAL := 3.14;
➢ Each variable or constant must be specified with its
name, type, and, optionally, initial value. All the rows
must end with a semicolon:
DECLARE
Cust_name varchar2 (20);
Credit number (5,2) : = 100;
13. PL/SQL BLOCK - Execution Section
➢ This section begins with the Begin declaration.
➢ This section can contain SQL commands, logical
control commands, and assignment commands, as well
as other commands.
➢ All commands are always end with a semicolon.
14. PL/SQL BLOCK - Exception
➢ In this section, the developer can use commands to
handle an error that occurs during the execution of a
PL/SQL program.
15. How PL/SQL Works
➢ PL/SQL is an engine that makes up part of the Oracle
server.
➢ It executes the procedural commands and passes the
SQL commands for the Oracle server to process.
➢ PL/SQL blocks can be created with any of the
processing editors. (Ex: Windows Notepad)
➢ To execute a PL/SQL program or script, you can use
SQL*Plus, which allows creating, storing, and
executing PL/SQL blocks.
19. Control Structures
➢ PL/SQL has some commands to control the execution
flow of the program. They are responsible for decision
making inside the application.
➢ control structures in PL/SQL, which can be divided
into condition control structures (selection), sequence
structures, and repetition or iteration structures.
➢ Different types of structure explained in the figure
15.3.
21. The IF..THEN Command
➢ The IF..THEN command evaluates a condition and
executes one or more rows of commands only if the
analyzed condition is true.
➢ It has two variations as follows:
22. The IF..THEN Command
➢ In syntax1, the commands that appear between the
THEN and END IF clauses will be executed only if
the condition is true.
Example:
declare
sal number(7,2);
begin
select salary into sal from emp2 where eno=101;
IF SAL>= 5000 THEN
UPDATE EMP2 SET salary = salary*1.2;
END IF;
dbms_output.put_line(sal);
end;
/
23. The IF..THEN Command
In syntax2, more than one condition can be analyzed
and, therefore, several actions can be executed:
1. create table emp2(eno number(3), salary number(7,2))
2. insert into emp2 values (102, 1500)
3. Type the following program and execute:
declare
sal number(7,2);
begin
select salary into sal from emp2 where eno=101;
IF sal<2000 THEN
UPDATE EMP2 SET salary = salary * 1.2;
ELSIF sal <3000 THEN
UPDATE EMP2 SET salary = salary * 1.3;
ELSE
UPDATE EMP2 SET salary = salary * 1.4;
END IF;
dbms_output.put_line(sal);
end;
24. The IF..THEN Command
➢ If the main condition is true, the following commands
will be executed until another ELSIF or ELSE clause
is found.
➢ If the first ELSIF condition is false, the program tests
the second condition, and so on.
➢ When the first true condition is found, its commands
are executed, and the program jumps to the row after
the END IF command.
25. The LOOP Command
➢ The LOOP command initializes a group of commands
indefinitely, or until a condition forces a “break” in the
loop and the execution of the program to another
place.
➢ The EXIT command is responsible for interrupting the
loop execution:
26. The LOOP Command - Example
LOOP with IF Loop with WHEN
declare
I number(3);
begin
I := 1;
Loop
I := I+1;
DBMS_OUTPUT.PUT_LINE(I);
IF I>= 30 THEN
EXIT;
END IF;
END LOOP;
END;
/
declare
I number(3);
begin
I := 1;
Loop
I := I+1;
DBMS_OUTPUT.PUT_LINE(I);
EXIT WHEN I>= 30;
END LOOP;
END;
/
➢ The following loop repeated until the counter variable
I become 30.
27. The FOR..LOOP Command
➢ The FOR..LOOP command is a variation of the LOOP
command.
➢ Here, the commands are automatically executed until
an evaluated condition returns false.
Syntax:
FOR <counter> IN [REVERSE] <initial_value> . . <final_value>
LOOP
<commands>
END LOOP;
28. The FOR LOOP Command - Example
Example:
declare
j number(3);
begin
FOR j IN 1..10
LOOP
DBMS_OUTPUT.PUT_LINE(j);
END LOOP;
END;
/
➢ The FOR command initializes a control variable called J, which
has the initial value of 1.
➢ The commands will be executed until END LOOP is found.
➢ Then, the control returns to the FOR command, which
increments the variable and analyzes the master condition, i.e.,
whether the value of J is less than the final value.
➢ When this happens the cycle is reinitialized.
29. The FOR LOOP Command - Example
➢ The REVERSE clause makes the counter start with the
highest value and decrease until it reaches the lowest
value.
declare
j number(3);
begin
FOR j IN reverse 1..10
LOOP
DBMS_OUTPUT.PUT_LINE(j);
END LOOP;
END;
/
30. The WHILE Command
➢ The WHILE command is another control structure.
This structure only executes the commands if the
analyzed condition is true.
declare
x number(3);
begin
x:=1;
while x<=20 loop
DBMS_OUTPUT.PUT_LINE(x);
x:=x+1;
END LOOP;
END;
/
31. Integrating SQL in a PL/SQL Program
➢ SQL commands can be inserted in the execution
section of a PL/SQL block.
➢ The developer can use (reference) a variable or
constant declared in the declaration section.
➢ Inside a PL/SQL program the SELECT command uses
a new clause called INTO that allows transferring the
contents of the fields in a row to the variables in
memory.
➢ Command: SET SERVEROUTPUT ON, GET
(Retreive the file), RUN (@ Execute the program)
32. Integrating SQL in a PL/SQL Program
Declare
Var_name number (7,2) ;
Begin
SELECT salary INTO Var_name FROM emp2 where eno
= 101;
dbms_output.put_line('salary=' || Var_name);
End;
/
➢ Note that to attribute contents to a field in a variable,
the SELECT command must return only one row;
➢ otherwise an error will occur, since several values are
being assigned to only one variable.