PL/SQL is a procedural language extension for SQL and the Oracle relational database. It allows developers to perform transactions in an Oracle database, define and control cursors, handle exceptions, and provide a host language for SQL. PL/SQL code is organized into logical blocks with optional declaration, mandatory executable, and optional exception handling sections. It provides benefits like improved performance, portability, and integration with SQL.
Users hate to wait - for anything. For our applications to be successful, they not only must be correct (meet user requirements) and maintainable. They must also execute efficiently enough to avoid user frustration. This presentation offers a whirlwind introduction to the most important techniques for improving PL/SQL performance, including data caching, FORALL and BULK COLLECT, the function result cache and the new 12.1 UDF pragma. It will help you proactively identify opportunities for applying techniques that will most dramatically (generally, an order or magnitude or more) improve the performance of your PL/SQL code. https://oracle.com/plsql
PL/Scope is a compiler tool that gathers information about identifiers (as of 11.1) and SQL statements (as of 12.2) in your PL/SQL code. You can do all sorts of amazing deep-dive analysis of your code with PL/Scope, answering questions like: Where is a variable assigned a value in a program? What variables are declared inside a given program? Which programs call another program (that is, you can get down to a subprogram in a package)? Find the type of a variable from its declaration. Show where specific columns are referenced. Locate all SQL statements containing hints. Find all dynamic SQL usages – ideal for getting rid of SQL injection vulnerabilities. Show all locations in your code where you commit or rollback. In other words, powerful impact analysis, built right into PL/SQL!
Cursores en Oracle PL/SQL, en esta presentación se encuentra información sobre que son, cuando se debe usar, su creación, invocación y también su eliminación.
pipelining is the concept of decomposing the sequential process into number of small stages in which each stage execute individual parts of instruction life cycle inside the processor.
Function in PL/SQL, Create Function Syntax, Example – No Parameters in Function , Example – Testing RetrieveSalary Function, Example Function with Parameter, Dropping a Function
PL/SQL is a combination of SQL along with the procedural features of programming languages.
It provides specific syntax for this purpose and supports exactly the same datatypes as SQL.
It consists of important different concepts related to PL/SQL that are covered like the Basic structure of PL/SQL block, Variables and Constants in PL/SQL, Control Structures i.e., Conditional, Iterative, and Sequential Control, Procedure and Function, Cursors and its Types, Applications of implicit and explicit cursors, Triggers and its Types and Exception Handling.
Need for PL/SQL,Benefits of Using PL/SQL,PL/SQL Block Types and Constructs,PL/SQL Block Structure,Operators and SQL Functions in PL/SQL,Variables,Nested Blocks.
Users hate to wait - for anything. For our applications to be successful, they not only must be correct (meet user requirements) and maintainable. They must also execute efficiently enough to avoid user frustration. This presentation offers a whirlwind introduction to the most important techniques for improving PL/SQL performance, including data caching, FORALL and BULK COLLECT, the function result cache and the new 12.1 UDF pragma. It will help you proactively identify opportunities for applying techniques that will most dramatically (generally, an order or magnitude or more) improve the performance of your PL/SQL code. https://oracle.com/plsql
PL/Scope is a compiler tool that gathers information about identifiers (as of 11.1) and SQL statements (as of 12.2) in your PL/SQL code. You can do all sorts of amazing deep-dive analysis of your code with PL/Scope, answering questions like: Where is a variable assigned a value in a program? What variables are declared inside a given program? Which programs call another program (that is, you can get down to a subprogram in a package)? Find the type of a variable from its declaration. Show where specific columns are referenced. Locate all SQL statements containing hints. Find all dynamic SQL usages – ideal for getting rid of SQL injection vulnerabilities. Show all locations in your code where you commit or rollback. In other words, powerful impact analysis, built right into PL/SQL!
Cursores en Oracle PL/SQL, en esta presentación se encuentra información sobre que son, cuando se debe usar, su creación, invocación y también su eliminación.
pipelining is the concept of decomposing the sequential process into number of small stages in which each stage execute individual parts of instruction life cycle inside the processor.
Function in PL/SQL, Create Function Syntax, Example – No Parameters in Function , Example – Testing RetrieveSalary Function, Example Function with Parameter, Dropping a Function
PL/SQL is a combination of SQL along with the procedural features of programming languages.
It provides specific syntax for this purpose and supports exactly the same datatypes as SQL.
It consists of important different concepts related to PL/SQL that are covered like the Basic structure of PL/SQL block, Variables and Constants in PL/SQL, Control Structures i.e., Conditional, Iterative, and Sequential Control, Procedure and Function, Cursors and its Types, Applications of implicit and explicit cursors, Triggers and its Types and Exception Handling.
Need for PL/SQL,Benefits of Using PL/SQL,PL/SQL Block Types and Constructs,PL/SQL Block Structure,Operators and SQL Functions in PL/SQL,Variables,Nested Blocks.
What does PL_SQL stand for and what is the functioning of PL_SQL.docxshivanikaale214
PL/SQL, Oracle's procedural extension to SQL, facilitates the creation of modular, efficient, and error-resilient code for database-centric applications. Mastering PL/SQL unlocks lucrative career prospects in database management and programming, offering essential skills for navigating the dynamic landscape of data management.
Answer and provide 1 reference. Advanced SQL and PLSQLE.docxSHIVA101531
Answer and provide 1 reference.
Advanced SQL and PL/SQL
Extracting and interpreting data can be very valuable to an organization. Describe the importance of using sub queries in a database system. Provide at least two business case scenarios to support your response.
A good IT professional is able to be versatile in SQL programming styles. Identify at least two possible advantages of utilizing PL/SQL instead of standard SQL Syntax. Explain whether either syntax provides enhanced code processing capabilities with examples.
Respond to this discussion Response:
Sub queries are important and advantageous because they are structured in such a way that they isolate each part of the statement, and perform the same operation that would ordinarily require complex and joins and unions and they ae easier to read. Base on how the database optimizer processes them can cause them the take longer to execute. The Structured Query Language (SQL) provide the basis for sub queries due to its easily readable structure. They provide a powerful means to combine data from two tables into a single result. Sub queries are also known as nested query or inner query such as defined by Covrett stating that “A subquery is a "SELECT" statement within the "WHERE" or "HAVING" clause of an outer "INSERT," "UPDATE," "MERGE" or "DELETE" statement. The subquery also is called the "inner query" or "inner select." The subquery may have a "FROM" clause with one or more tables and may optionally have a "WHERE," "GROUP BY" or "HAVING" clause. It is always enclosed in parenthesis.”
PL/SQL is an extension of Structured Query Language (SQL) that is used in oracle. It allows the programmer to write code in a procedural format. It’s purpose is to combine database language and procedural programming language.
Advantages of PL/SQL:
Tight Integration with SQL.
High Performance.
High Productivity.
Portability.
Scalability.
Manageability.
Support for Object-Oriented Programming.
Support for Developing Web Applications.
Covrett, L. What Are the Advantages & Disadvantages of a Join or a Subquery? https://www.techwalla.com/articles/what-are-the-advantages-disadvantages-of-a-join-or-a-subquery
.
1. In a 200 words or less explain the differences between SQL and .docxSONU61709
1. In a 200 words or less explain the differences between SQL and PL/SQL? Why do we need SQL in a procedural language?
2. Respond to the following in 100 words—APA Format and Cite work
SA
SQL is a structured query language that is used to retrieve and manipulate data as well as create and modify objects in a database. There are some capabilities for logic in SQL statements such as case and decode statements, but it is very limited. PL/SQL is a procedural language that has many more logic options available such as if-else statements and for loops. However, PL/SQL isn’t very useful without SQL to retrieve and manipulate the data. For instance, you can use SQL to retrieve a value from a table and based on the value; use an if-else statement to choose to update a value in another table or not. PL/SQL also has a few other features that make it more efficient than just SQL alone. One being that PL/SQL transmits multiple SQL statements at one time in a block whereas SQL sends each statement separately thus saving bandwidth. Another is that PL/SQL that is stored in the database as a program unit is stored in executable form and is cached in memory making it more efficient to run (Casteel, 2013, pp. 3-4).
Reference:
Casteel, J. (2013). Oracle 11g: PL/SQL programming. Boston, MA: Course Technology, Cengage Learning.
---------------------------------------------------------------------------------------------------------------------
3. Respond to the following in 100 words—APA Format and Cite work
Structured Query Language (SQL) is used primarily to conduct various actions within a database. These actions are typically categorized as data manipulation (DML), data definition (DDL), querying, and transaction control. DML includes actions like insertion, update, deletion. DDL includes, alteration, creation, and dropping. Queries are performed via select statements, and transaction control can be conducted via commit and rollback statements (Casteel, 2013, p. 15).
PL/SQL is Oracle's procedural language extension of SQL. Procedural languages are used to design logic statements which control decision making and the flow of information which makes a system conduct tasks. By extending procedural language to SQL, programmers gain the ability to perform traditional programming logic alongside SQL statements. The textbook example points out the use of PL/SQL to validate a customer input by checking database details after a customer has conducted a certain action. Using PL/SQL can improve performance by packaging multiple statements, increase productivity through enhanced integration, increased portability, and better security (Casteel, 2013, p. 4).
Reference
Casteel, J. (2013). Oracle 11g: PL/SQL Programming (2nd ed.). Boston, MA: Course Technology.
1.
In a 2
00 words or less explain the
differences between SQL and PL/SQL? Why do we need SQL in
a procedural language?
2.
Respond
to the following
in 100 words
—
APA
Format and Cite
work
SA
SQ ...
Presenter manual oracle D2K (specially for summer interns)XPERT INFOTECH
XPERT INFOTECH imparts qualitative training in .NET, ASP.NET, PHP, PHP++, JAVA, J2EE, ORACLE DBA, ORALE D2K, RIA, SEO, WEB DEVELOPMENT, MOBILE APPLICATIONS DEVELOPMENT, ANDROID and other latest technologies. The training is designed for the BCA/MCA/B.E./B-Tech students who want to speed up their technical skills and proficiencies into real time development environment.
C Programming : Arrays, One Dimensional Arrays, Two Dimensional Arrays, Three Dimensional Arrays, Operations on Arrays like Insertion, Deletion, Searching, Sorting, Merging, Traversing, Matrix Manipulation like Addition, Multiplication etc. : Visit us at : www.rozyph.com
C lecture 4 nested loops and jumping statements slideshareGagan Deep
Nested Loops and Jumping Statements(Loop Control Statements), Goto statement in C, Return Statement in C Exit statement in C, For Loops with Nested Loops, While Loop with Nested Loop, Do-While Loop with Nested Loops, Break Statement, Continue Statement : visit us at : www.rozyph.com
C lecture 3 control statements slideshareGagan Deep
Control Statement in C, Looping in C, Conditional and Unconditional Statements, For Loop, While Loop, Do-While Loop, C Programming, Examples : Visit us at www.rozyph.com
1. PL/SQL - Overview
Gagan Deep
Assistant Professor
University College,
Kurukshetra University, Kurukshetra
2. 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.
Gagan Deep, Assistant Professor, UCK and Director, Rozy Computech Services, 3 rd Gate, K.U., Kurukshetra
3. PL/SQL
The PL/SQL procedural
language was developed by
Oracle Corporation in the late
1980s as procedural extension
language for SQL and the Oracle relational database.
Following are 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.
Gagan Deep, Assistant Professor, UCK and Director, Rozy Computech Services, 3 rd Gate, K.U., Kurukshetra
4. • 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.
Gagan Deep, Assistant Professor, UCK and Director, Rozy Computech Services, 3 rd Gate, K.U., Kurukshetra
5. Why PL/SQL
• Acts as host language for
stored procedures and triggers.
• Provides the ability to add
middle tier business logic to
client/server applications.
• Provides Portability of code from one
environment to another
• Improves performance of multi-query
transactions.
• Provides error handling
Gagan Deep, Assistant Professor, UCK and Director, Rozy Computech Services, 3 rd Gate, K.U., Kurukshetra
6. Features of PL/SQL
PL/SQL has the following features:
• PL/SQL is tightly integrated with
SQL.
• It offers extensive error checking.
• It offers numerous data types.
• It offers a variety of programming structures.
• It supports structured programming through functions
and procedures.
• It supports object oriented programming.
• It supports developing web applications and server
pages.
Gagan Deep, Assistant Professor, UCK and Director, Rozy Computech Services, 3 rd Gate, K.U., Kurukshetra
7. Advantages of PL/SQL
PL/SQL has the following
advantages :
•SQL is the standard database
language and PL/SQL is
strongly integrated with SQL. PL/SQL supports
both static and dynamic SQL.
• Static SQL supports DML operations and
transaction control from PL/SQL block.
• Dynamic SQL is SQL allows embedding DDL
statements in PL/SQL blocks.
Gagan Deep, Assistant Professor, UCK and Director, Rozy Computech Services, 3 rd Gate, K.U., Kurukshetra
8. • PL/SQL allows sending an
entire block of statements to the
database at one time. This
reduces network traffic and
provides high performance for
the applications.
• PL/SQL give high productivity to programmers as
it can query, transform, and update data in a
database.
• PL/SQL saves time on design and debugging by
strong features, such as exception handling,
encapsulation, data hiding, and object-oriented.
Gagan Deep, Assistant Professor, UCK and Director, Rozy Computech Services, 3 rd Gate, K.U., Kurukshetra
9. • Applications written in
PL/SQL are fully portable.
• PL/SQL provides high
security level.
• PL/SQL provides access to
predefined SQL packages.
• PL/SQL provides support for Object-Oriented
Programming.
• PL/SQL provides support for Developing Web
Applications and Server Pages.
Gagan Deep, Assistant Professor, UCK and Director, Rozy Computech Services, 3 rd Gate, K.U., Kurukshetra
10. Client-Server Architecture
• PL/SQL is a part of the Oracle RDBMS, and it can reside
in two environments, the client and the server.
• Many Oracle applications are built using client-server
architecture.
The Oracle database resides on the server.
• The program(` C, Java, or PL/SQL) that makes requests
against this database resides on the client machine.
• As a result, it is very easy to move PL/SQL modules
between server-side and client-side applications.
• When the PL/SQL engine is located on the server, the
whole PL/SQL block is passed to the PL/SQL engine on
the Oracle server. The PL/SQL engine processes the
block according to the Figure 1.
11. Figure 1 : The PL/SQL Engine and
Oracle Server
12. • When the PL/SQL engine
is located on the client, as
it is in the Oracle
Developer Tools, the
PL/SQL processing is
done on the client side.
• All SQL statements that are embedded within
the PL/SQL block are sent to the Oracle
server for further processing. When PL/SQL
block contains no SQL statement, the entire
block is executed on the client side.
13. Comparison of PL/SQL
and SQL
• When a SQL statement is issued on
the client computer, the request is
made to the database on the server,
and the result set is sent back to the
client.
• As a result, a single SQL statement causes two trips on the
network. If multiple SELECT statements are issued, the
network traffic increase significantly very fast. For example,
four SELECT statements cause eight network trips.
• If these statements are part of the PL/SQL block, they are
sent to the server as a single unit. The SQL statements in this
PL/SQL program are executed at the server and the result set
is sent back as a single unit. There is still only one network
trip made as is in case of a single SELECT statement.
14. Comparison of PL/SQL
and SQL
Figure 2 : The PL/SQL in client –
server architecture
15. PL/SQL Block-Structure
PL/SQL is a block-structured
language, meaning that PL/SQL
programs are divided and written
in logical blocks of code. Each
block consists of three sub-parts:
1 Declarations :
This section starts with the keyword DECLARE.
It is an optional section and defines all
variables, cursors, subprograms, and other
elements to be used in the program.
Gagan Deep, Assistant Professor, UCK and Director, Rozy Computech Services, 3 rd Gate, K.U., Kurukshetra
16. 2 Executable Commands
This section is enclosed between
the keywords BEGIN and
END and it is a mandatory
section. It consists of the
executable PL/SQL statements
of the program. It should have
at least one executable line of
code, which may be just a
NULL command to indicate
that nothing should be
executed.
Gagan Deep, Assistant Professor, UCK and Director, Rozy Computech Services, 3 rd Gate, K.U., Kurukshetra
17. 3 Exception Handling
This section starts with the
keyword EXCEPTION.
This section is again optional
and contains exception(s)
that handle errors in the
program.
Every PL/SQL statement end with a semicolon
(;).
PL/SQL blocks can be nested within other
PL/SQL blocks using BEGIN and END.
Gagan Deep, Assistant Professor, UCK and Director, Rozy Computech Services, 3 rd Gate, K.U., Kurukshetra
18. PL/SQL Block Structure
DECLARE (optional)
- variable declarations
BEGIN (mandatory)
- SQL statements
- PL/SQL statements or sub-
blocks
EXCEPTION (optional)
- actions to perform when errors
occur
END; (mandatory)
Gagan Deep, Assistant Professor, UCK and Director, Rozy Computech Services, 3 rd Gate, K.U., Kurukshetra
19. PL/SQL Block Types
Function
Anonymous Procedure FUNCTION <name>
RETURN <datatype>
DECLARE PROCEDURE <name>
IS
BEGIN IS
BEGIN
-statements BEGIN
-statements
EXCEPTION -statements
EXCEPTION
END; EXCEPTION
END;
END;
Gagan Deep, Assistant Professor, UCK and Director, Rozy Computech Services, 3 rd Gate, K.U., Kurukshetra
20. Example
The end; line
signals the end of
the PL/SQL block.
DECLARE
message varchar2(20):= 'Hello, World!'; To run the code
BEGIN from SQL command
dbms_output.put_line(message); line, you may need
END; to type / at the
/ beginning of the
Hello, World ! first blank line after
PL/SQL procedure successfully the last line of the
completed.
code.
Gagan Deep, Assistant Professor, UCK and Director, Rozy Computech Services, 3 rd Gate, K.U., Kurukshetra
21. The PL/SQL Identifiers
• PL/SQL identifiers are constants,
variables, exceptions, procedures,
cursors, and reserved words. The
identifiers consist of a letter
optionally followed by more,
letters numerals, dollar signs, underscores, and
number signs and should not exceed 30 characters.
•By default, identifiers are not case-sensitive. So
you can use integer or INTEGER to represent a
numeric value. You cannot use a reserved keyword as
an identifier.
Gagan Deep, Assistant Professor, UCK and Director, Rozy Computech Services, 3 rd Gate, K.U., Kurukshetra
22. The PL/SQL Delimiters
A delimiter is a symbol with a special
meaning. Following is the list of
delimiters in PL/SQL:
Delimiter Description
Addition, subtraction/negation,
+, -, *, / multiplication, division
% Attribute indicator
' Character string delimiter
. Component selector
(,) Expression or list delimiter
Similarly, there are : Host variable indicator
more delimiters. , Item separator
Gagan Deep, Assistant Professor, UCK and Director, Rozy Computech Services, 3 rd Gate, K.U., Kurukshetra
23. The PL/SQL Comments
• Program comments are explanatory statements that you
can include in the PL/SQL code that you write and
helps anyone reading it's source code. All
programming languages allow for some form of
comments.
• The PL/SQL supports single line and multi-line
comments. All characters available inside any
comment are ignored by PL/SQL compiler. The
PL/SQL single-line comments start with the delimiter
-- (double hyphen) and multi-line comments are
enclosed by /* and */.
Gagan Deep, Assistant Professor, UCK and Director, Rozy Computech Services, 3 rd Gate, K.U., Kurukshetra
24. DECLARE
-- variable declaration
message varchar2(20):= 'Hello,
World!’;
BEGIN
/*
PL/SQL executable statement(s)
Example */
dbms_output.put_line(message);
END;
/
After Execution in SQL the result is : Hello, World!
PL/SQL procedure successfully completed.
Gagan Deep, Assistant Professor, UCK and Director, Rozy Computech Services, 3 rd Gate, K.U., Kurukshetra
25. Data Types
PL/SQL variables, constants and parameters must have
a valid data types which specifies a storage format,
constraints, and valid range of values. PL/SQL is
strongly typed. The following is the list of data types:
Category Description
Single values with no internal components,
Scalar such as a NUMBER, DATE, or BOOLEAN.
Pointers to large objects that are stored
separately from other data items, such as
Large Object (LOB) text, graphic images, video clips, and sound
waveforms.
Data items that have internal components
Composite that can be accessed individually. For
example, collections and records.
Reference Pointers to other data items.
Gagan Deep, Assistant Professor, UCK and Director, Rozy Computech Services, 3 rd Gate, K.U., Kurukshetra
26. Scalar Data Types
• PL/SQL Scalar Data Types and
Subtypes come under the following
categories:
Date Type Description
Numeric values, on which arithmetic operations
Numeric are performed.
Alphanumeric values that represent single
Character characters or strings of characters.
Logical values, on which logical operations are
Boolean performed.
Datetime Dates and times.
Gagan Deep, Assistant Professor, UCK and Director, Rozy Computech Services, 3 rd Gate, K.U., Kurukshetra
27. PL/SQL Numeric Data
Types
Data Type Description
ANSI and IBM specific floating-point type
FLOAT with maximum precision of 126 binary digits
(approximately 38 decimal digits)
ANSI and IBM specific integer type with
INTEGER OR INT
maximum precision of 38 decimal digits
Floating-point type with maximum precision
REAL of 63 binary digits (approximately 18 decimal
digits)
Signed integer in range -2,147,483,648
PLS_INTEGER OR BINARY_INTEGER
through 2,147,483,647, represented in 32 bits
ANSI specific fixed-point type with
DEC(prec, scale)
maximum precision of 38 decimal digits.
Gagan Deep, Assistant Professor, UCK and Director, Rozy Computech Services, 3 rd Gate, K.U., Kurukshetra
28. Following is a valid declaration:
DECLARE
num1 INTEGER;
num2 REAL;
num3 DOUBLE PRECISION;
BEGIN
Example null;
END;
/
When the above code is compiled and executed, it
produces following result:
PL/SQL procedure successfully completed
Gagan Deep, Assistant Professor, UCK and Director, Rozy Computech Services, 3 rd Gate, K.U., Kurukshetra
29. Character Data Types
Data Type Description
CHAR Fixed-length character string with maximum size of 32,767 bytes
VARCHAR Variable-length character string with maximum size of 32,767
2 bytes
Variable-length binary or byte string with maximum size of
RAW 32,767 bytes, not interpreted by PL/SQL
Variable-length character string with maximum size of 32,760
LONG bytes
ROWID Physical row identifier, the address of a row in an ordinary table
Gagan Deep, Assistant Professor, UCK and Director, Rozy Computech Services, 3 rd Gate, K.U., Kurukshetra
30. PL/SQL Operators
An operator is a symbol that tells the
compiler to perform specific
mathematical or logical manipulations.
PL/SQL language is rich in built-in
operators and provides following type
of operators:
•Arithmetic operators
•Relational operators
•Comparison operators
•Logical operators
•String operators
Gagan Deep, Assistant Professor, UCK and Director, Rozy Computech Services, 3 rd Gate, K.U., Kurukshetra
31. Precedence of Operators
Operator Operation
** exponentiation
+, - identity, negation
*, / multiplication, division
+, -, || addition, subtraction, concat
=, <, >, <=, >=, IS NULL, LIKE, IN Comparison
NOT logical negation
AND conjunction
OR inclusion
Gagan Deep, Assistant Professor, UCK and Director, Rozy Computech Services, 3 rd Gate, K.U., Kurukshetra
32. Control Structures
• Programming languages provide
various control structures that
allow for more complicated
execution paths.
• Decision making structures require that the
programmer specify one or more conditions to be
evaluated or tested by the program, along with a
statement or statements to be executed if the
condition is determined to be true, and optionally,
other statements to be executed if the condition is
determined to be false.
Gagan Deep, Assistant Professor, UCK and Director, Rozy Computech Services, 3 rd Gate, K.U., Kurukshetra
33. PL/SQL Decisions
Making
PL/SQL language provides
following types of decision
making statements.
•IF-THEN Statement
•IF-THEN-ELSE Statement
•IF-THEN-ELSEIF Statement
•Nested IF Statement
Gagan Deep, Assistant Professor, UCK and Director, Rozy Computech Services, 3 rd Gate, K.U., Kurukshetra
34. Syntax for IF-THEN statement
IF condition THEN
S;
END IF;
Where condition is a Boolean or relational
condition and S is a simple or compound
statement.
Example of an IF-THEN statement is:
IF (a <= 20) THEN
c:= c+1;
END IF;
Gagan Deep, Assistant Professor, UCK and Director, Rozy Computech Services, 3 rd Gate, K.U., Kurukshetra
35. DECLARE Example
a number(2) := 10;
BEGIN
a:= 10;
IF( a < 20 ) THEN
dbms_output.put_line('a is less than 20' );
END IF;
dbms_output.put_line('value of a is:' || a);
END;
/ After Execution :
a is less than 20 value of a is : 10
PL/SQL procedure successfully completed.
Gagan Deep, Assistant Professor, UCK and Director, Rozy Computech Services, 3 rd Gate, K.U., Kurukshetra
36. PL/SQL - Loops
PL/SQL provides the following
types of loop to handle the looping
requirements
•BASIC LOOP
•WHILE LOOP
•FOR LOOP
•NESTED LOOP
Gagan Deep, Assistant Professor, UCK and Director, Rozy Computech Services, 3 rd Gate, K.U., Kurukshetra
37. Syntax of Basic Loop
The syntax of a basic loop in PL/SQL language
is:
LOOP
Sequence of statements;
END LOOP
Gagan Deep, Assistant Professor, UCK and Director, Rozy Computech Services, 3 rd Gate, K.U., Kurukshetra
38. Example
DECLARE
x number := 10;
BEGIN LOOP
dbms_output.put_line(x);
x := x + 10;
IF x > 50 THEN exit; END IF;
END LOOP;
dbms_output.put_line('After Exit x is: ' || x);
END;
/
After Execution is : 10 20 30 40 50 After Exit x is: 60
Gagan Deep, Assistant Professor, UCK and Director, Rozy Computech Services, 3 rd Gate, K.U., Kurukshetra
39. Syntax of For Loop
FOR counter IN i_value .. f_value LOOP
sequence_of_statements;
END LOOP;
Following are special characteristics of FOR loop:
The i_value and f_value of the loop variable or counter can
be literals, variables, or expressions but must evaluate to
numbers. Otherwise, PL/SQL raises the predefined
exception VALUE_ERROR.
The i_value need not to be 1; however, the loop counter
increment (or decrement) must be 1.
PL/SQL allows determine the loop range dynamically at
runGagan Deep, Assistant Professor, UCK and Director, Rozy Computech Services, 3 Gate, K.U., Kurukshetra
time. rd
40. Example
DECLARE
a number(2);
BEGIN
Result is
FOR a in 10 .. 15 LOOP
value of a: 10
dbms_output.put_line('value of a: ' ||
value of a: 11
a);
value of a: 12
END LOOP;
value of a: 13
END;
value of a: 14
/
value of a: 15
Gagan Deep, Assistant Professor, UCK and Director, Rozy Computech Services, 3 rd Gate, K.U., Kurukshetra
43. When is PL/SQL
handy
• When something is too
complicated for SQL
• When conditional branching
and looping are needed.
Gagan Deep, Assistant Professor, UCK and Director, Rozy Computech Services, 3 rd Gate, K.U., Kurukshetra
44. Thanks !
If you have any query please mail me at
rozygag@yahoo.com