This document provides an overview of PL/SQL including:
- PL/SQL block structure with declare, execution, and exception sections
- Variables, constants, datatypes
- Control structures like IF/ELSE statements and loop structures
- Procedures and functions
- Uses of PL/SQL include combining SQL with procedural logic, writing reusable code, and handling exceptions.
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.
The document discusses PL/SQL, a programming language extension of SQL that adds procedural language features. It defines PL/SQL blocks and their components. It describes advantages like better performance and error handling. It also covers conditional statements, iterative statements, cursors, stored procedures, functions, exception handling, triggers, and embedded SQL in PL/SQL.
This document provides an introduction to PL/SQL, including PL/SQL block structure, data types, variables, control structures, and more. PL/SQL combines procedural language elements with SQL statements to enhance database programming capabilities. Key elements include DECLARE, BEGIN, and END sections in a PL/SQL block; data types like NUMBER, VARCHAR2, DATE; variables and constants; control structures like IF-THEN-ELSE; and functions for output.
PL/SQL extends SQL with procedural language capabilities. It allows variables, control structures like IF/THEN statements, and subprograms. The basic unit is a block that declares variables, contains an executable section, and can handle exceptions. Blocks can be anonymous, named, stored as subprograms or triggers. Cursors allow processing query result sets row by row. Variables and attributes simplify code maintenance. Packages and modularization improve program organization. Error handling uses exceptions to manage runtime errors gracefully.
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.
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 is a procedural language designed specifically to embrace SQL statements within its syntax. PL/SQL program units are compiled by the Oracle Database server and stored inside the database.
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.
The document discusses PL/SQL, a programming language extension of SQL that adds procedural language features. It defines PL/SQL blocks and their components. It describes advantages like better performance and error handling. It also covers conditional statements, iterative statements, cursors, stored procedures, functions, exception handling, triggers, and embedded SQL in PL/SQL.
This document provides an introduction to PL/SQL, including PL/SQL block structure, data types, variables, control structures, and more. PL/SQL combines procedural language elements with SQL statements to enhance database programming capabilities. Key elements include DECLARE, BEGIN, and END sections in a PL/SQL block; data types like NUMBER, VARCHAR2, DATE; variables and constants; control structures like IF-THEN-ELSE; and functions for output.
PL/SQL extends SQL with procedural language capabilities. It allows variables, control structures like IF/THEN statements, and subprograms. The basic unit is a block that declares variables, contains an executable section, and can handle exceptions. Blocks can be anonymous, named, stored as subprograms or triggers. Cursors allow processing query result sets row by row. Variables and attributes simplify code maintenance. Packages and modularization improve program organization. Error handling uses exceptions to manage runtime errors gracefully.
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.
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 is a procedural language designed specifically to embrace SQL statements within its syntax. PL/SQL program units are compiled by the Oracle Database server and stored inside the database.
PL/SQL is a database-oriented programming language that extends SQL with procedural capabilities like condition checking, looping, and branching. It allows programmers to handle errors and display user-friendly error messages. PL/SQL code is organized into declarative regions, and it can define variables, constants, cursors, procedures, and functions. Cursors are used to process result sets from a SQL query row by row.
This document provides an introduction to PL/SQL, including what PL/SQL is, why it is used, its basic structure and components like blocks, variables, and types. It also covers key PL/SQL concepts like conditions, loops, cursors, stored procedures, functions, and triggers. Examples are provided to illustrate how to write and execute basic PL/SQL code blocks, programs with variables, and stored programs that incorporate cursors, exceptions, and other features.
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.
This document provides an overview and programming tips for using SQL procedural language (SQL PL) stored procedures on DB2 for z/OS. It discusses various features and enhancements for SQL PL including compound blocks, templates, dynamic SQL, XML support, array data types, global variables, and autonomous transactions. The document also provides examples and best practices for writing SQL procedures, including handling naming resolution, using templates for readability, and working with arrays and dynamic SQL.
PL/SQL is a programming language that combines the SQL operations of querying and manipulating data in an Oracle database with the procedural language constructs of variables, conditions, and loops. PL/SQL can be used for database-side programming as well as client-side application development. It provides advantages like better performance, portability, higher productivity, and integration with Oracle. PL/SQL supports various data types, control structures, exception handling, and object-oriented programming features. Cursors allow processing of multiple rows returned from a SQL statement and can be static, dynamic, or reference types. Procedures and functions are reusable program units that allow passing parameters and returning values.
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
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.
PL/SQL is a combination of SQL and procedural languages that enhances SQL's capabilities. It allows processing of SQL statements as a block. A PL/SQL block consists of optional declaration, mandatory execution, and optional exception sections. Variables, constants, records can be declared in the declaration section and used in the execution section. The execution section contains the main program logic. Exceptions are handled in the exception section. PL/SQL supports programming constructs like conditional statements and loops.
Triggers in PL/SQL are blocks of code that are automatically executed in response to certain events or actions on a database table, such as INSERT, UPDATE or DELETE operations. There are different types of triggers including row-level triggers that fire for each row affected, statement-level triggers that fire once per SQL statement, and timing triggers that fire before or after the triggering statement. Triggers are useful for maintaining complex constraints, recording changes made to tables, and enforcing referential integrity. A trigger contains a triggering event, an optional trigger restriction, and the trigger action to be executed.
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.
PL/SQL is a procedural language extension for SQL that allows for the processing of SQL and procedural language elements. It was developed by Oracle Corporation to enhance the capabilities of SQL. PL/SQL code is organized into blocks that contain a declarative section, executable section, and exception section. It is an embedded language executed by the Oracle database server and is used for developing stored procedures and triggers.
This document provides an overview of PL/SQL programming. It outlines an agenda that introduces PL/SQL and covers basic and advanced syntax. The introduction defines PL/SQL and outlines its advantages like block structures, procedural capabilities, and error handling. Basic syntax covers blocks, operators, comments, variables and data types. Advanced topics include cursors, procedures, functions, parameters, and exception handling. Triggers are also introduced as PL/SQL blocks triggered by data changes. Examples are provided throughout to illustrate key PL/SQL concepts.
This document discusses various topics related to dynamic websites using PHP with Oracle DB including:
1. Quizzes on database relations and queries
2. Installing and connecting to Oracle 11g
3. Using SQL Developer tool
4. An overview of PL/SQL including blocks, conditions, loops
5. Stored procedures and functions
6. Triggers
7. Basic HTML markup
This document provides an agenda and overview for a two-day PL/SQL Fundamentals training course. The agenda covers key PL/SQL concepts like language features, the DECLARE, BEGIN, and EXCEPTION clauses, explicit cursors, nested blocks, and declared subprograms. Students will learn to program with PL/SQL using a sample COMPANY database that will be set up on Oracle Database Express Edition. The course is a prerequisite for more advanced PL/SQL trainings.
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 block-structured language used for accessing and manipulating Oracle databases. A PL/SQL block contains three parts: a declarative section, executable section, and exception-handling section. PL/SQL supports both scalar and composite datatypes. Control structures include conditional statements like IF-THEN-ELSE and CASE, and iterative statements like LOOP, WHILE, and FOR. Database interaction is done through SQL statements and cursors, which allow processing of multiple rows returned from a query.
A review of the growth of the Israel Genealogy Research Association Database Collection for the last 12 months. Our collection is now passed the 3 million mark and still growing. See which archives have contributed the most. See the different types of records we have, and which years have had records added. You can also see what we have for the future.
PL/SQL is a database-oriented programming language that extends SQL with procedural capabilities like condition checking, looping, and branching. It allows programmers to handle errors and display user-friendly error messages. PL/SQL code is organized into declarative regions, and it can define variables, constants, cursors, procedures, and functions. Cursors are used to process result sets from a SQL query row by row.
This document provides an introduction to PL/SQL, including what PL/SQL is, why it is used, its basic structure and components like blocks, variables, and types. It also covers key PL/SQL concepts like conditions, loops, cursors, stored procedures, functions, and triggers. Examples are provided to illustrate how to write and execute basic PL/SQL code blocks, programs with variables, and stored programs that incorporate cursors, exceptions, and other features.
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.
This document provides an overview and programming tips for using SQL procedural language (SQL PL) stored procedures on DB2 for z/OS. It discusses various features and enhancements for SQL PL including compound blocks, templates, dynamic SQL, XML support, array data types, global variables, and autonomous transactions. The document also provides examples and best practices for writing SQL procedures, including handling naming resolution, using templates for readability, and working with arrays and dynamic SQL.
PL/SQL is a programming language that combines the SQL operations of querying and manipulating data in an Oracle database with the procedural language constructs of variables, conditions, and loops. PL/SQL can be used for database-side programming as well as client-side application development. It provides advantages like better performance, portability, higher productivity, and integration with Oracle. PL/SQL supports various data types, control structures, exception handling, and object-oriented programming features. Cursors allow processing of multiple rows returned from a SQL statement and can be static, dynamic, or reference types. Procedures and functions are reusable program units that allow passing parameters and returning values.
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
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.
PL/SQL is a combination of SQL and procedural languages that enhances SQL's capabilities. It allows processing of SQL statements as a block. A PL/SQL block consists of optional declaration, mandatory execution, and optional exception sections. Variables, constants, records can be declared in the declaration section and used in the execution section. The execution section contains the main program logic. Exceptions are handled in the exception section. PL/SQL supports programming constructs like conditional statements and loops.
Triggers in PL/SQL are blocks of code that are automatically executed in response to certain events or actions on a database table, such as INSERT, UPDATE or DELETE operations. There are different types of triggers including row-level triggers that fire for each row affected, statement-level triggers that fire once per SQL statement, and timing triggers that fire before or after the triggering statement. Triggers are useful for maintaining complex constraints, recording changes made to tables, and enforcing referential integrity. A trigger contains a triggering event, an optional trigger restriction, and the trigger action to be executed.
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.
PL/SQL is a procedural language extension for SQL that allows for the processing of SQL and procedural language elements. It was developed by Oracle Corporation to enhance the capabilities of SQL. PL/SQL code is organized into blocks that contain a declarative section, executable section, and exception section. It is an embedded language executed by the Oracle database server and is used for developing stored procedures and triggers.
This document provides an overview of PL/SQL programming. It outlines an agenda that introduces PL/SQL and covers basic and advanced syntax. The introduction defines PL/SQL and outlines its advantages like block structures, procedural capabilities, and error handling. Basic syntax covers blocks, operators, comments, variables and data types. Advanced topics include cursors, procedures, functions, parameters, and exception handling. Triggers are also introduced as PL/SQL blocks triggered by data changes. Examples are provided throughout to illustrate key PL/SQL concepts.
This document discusses various topics related to dynamic websites using PHP with Oracle DB including:
1. Quizzes on database relations and queries
2. Installing and connecting to Oracle 11g
3. Using SQL Developer tool
4. An overview of PL/SQL including blocks, conditions, loops
5. Stored procedures and functions
6. Triggers
7. Basic HTML markup
This document provides an agenda and overview for a two-day PL/SQL Fundamentals training course. The agenda covers key PL/SQL concepts like language features, the DECLARE, BEGIN, and EXCEPTION clauses, explicit cursors, nested blocks, and declared subprograms. Students will learn to program with PL/SQL using a sample COMPANY database that will be set up on Oracle Database Express Edition. The course is a prerequisite for more advanced PL/SQL trainings.
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 block-structured language used for accessing and manipulating Oracle databases. A PL/SQL block contains three parts: a declarative section, executable section, and exception-handling section. PL/SQL supports both scalar and composite datatypes. Control structures include conditional statements like IF-THEN-ELSE and CASE, and iterative statements like LOOP, WHILE, and FOR. Database interaction is done through SQL statements and cursors, which allow processing of multiple rows returned from a query.
A review of the growth of the Israel Genealogy Research Association Database Collection for the last 12 months. Our collection is now passed the 3 million mark and still growing. See which archives have contributed the most. See the different types of records we have, and which years have had records added. You can also see what we have for the future.
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Dr. Vinod Kumar Kanvaria
Exploiting Artificial Intelligence for Empowering Researchers and Faculty,
International FDP on Fundamentals of Research in Social Sciences
at Integral University, Lucknow, 06.06.2024
By Dr. Vinod Kumar Kanvaria
Thinking of getting a dog? Be aware that breeds like Pit Bulls, Rottweilers, and German Shepherds can be loyal and dangerous. Proper training and socialization are crucial to preventing aggressive behaviors. Ensure safety by understanding their needs and always supervising interactions. Stay safe, and enjoy your furry friends!
Executive Directors Chat Leveraging AI for Diversity, Equity, and InclusionTechSoup
Let’s explore the intersection of technology and equity in the final session of our DEI series. Discover how AI tools, like ChatGPT, can be used to support and enhance your nonprofit's DEI initiatives. Participants will gain insights into practical AI applications and get tips for leveraging technology to advance their DEI goals.
it describes the bony anatomy including the femoral head , acetabulum, labrum . also discusses the capsule , ligaments . muscle that act on the hip joint and the range of motion are outlined. factors affecting hip joint stability and weight transmission through the joint are summarized.
A Strategic Approach: GenAI in EducationPeter Windle
Artificial Intelligence (AI) technologies such as Generative AI, Image Generators and Large Language Models have had a dramatic impact on teaching, learning and assessment over the past 18 months. The most immediate threat AI posed was to Academic Integrity with Higher Education Institutes (HEIs) focusing their efforts on combating the use of GenAI in assessment. Guidelines were developed for staff and students, policies put in place too. Innovative educators have forged paths in the use of Generative AI for teaching, learning and assessments leading to pockets of transformation springing up across HEIs, often with little or no top-down guidance, support or direction.
This Gasta posits a strategic approach to integrating AI into HEIs to prepare staff, students and the curriculum for an evolving world and workplace. We will highlight the advantages of working with these technologies beyond the realm of teaching, learning and assessment by considering prompt engineering skills, industry impact, curriculum changes, and the need for staff upskilling. In contrast, not engaging strategically with Generative AI poses risks, including falling behind peers, missed opportunities and failing to ensure our graduates remain employable. The rapid evolution of AI technologies necessitates a proactive and strategic approach if we are to remain relevant.
Main Java[All of the Base Concepts}.docxadhitya5119
This is part 1 of my Java Learning Journey. This Contains Custom methods, classes, constructors, packages, multithreading , try- catch block, finally block and more.
How to Build a Module in Odoo 17 Using the Scaffold MethodCeline George
Odoo provides an option for creating a module by using a single line command. By using this command the user can make a whole structure of a module. It is very easy for a beginner to make a module. There is no need to make each file manually. This slide will show how to create a module using the scaffold method.
Introduction to AI for Nonprofits with Tapp NetworkTechSoup
Dive into the world of AI! Experts Jon Hill and Tareq Monaur will guide you through AI's role in enhancing nonprofit websites and basic marketing strategies, making it easy to understand and apply.
हिंदी वर्णमाला पीपीटी, hindi alphabet PPT presentation, hindi varnamala PPT, Hindi Varnamala pdf, हिंदी स्वर, हिंदी व्यंजन, sikhiye hindi varnmala, dr. mulla adam ali, hindi language and literature, hindi alphabet with drawing, hindi alphabet pdf, hindi varnamala for childrens, hindi language, hindi varnamala practice for kids, https://www.drmullaadamali.com
Physiology and chemistry of skin and pigmentation, hairs, scalp, lips and nail, Cleansing cream, Lotions, Face powders, Face packs, Lipsticks, Bath products, soaps and baby product,
Preparation and standardization of the following : Tonic, Bleaches, Dentifrices and Mouth washes & Tooth Pastes, Cosmetics for Nails.
2. Overview..
Introduction
PL/SQL Block Structure
PL/SQL Variables
PL/SQL IF Statement
PL/SQL Loop Statement:
PL/SQL WHILE Loop Statement PL/SQL FOR Loop
Statement.
PL/SQL Function ; PL/SQL Procedure
Exceptions
Cursors and Triggers
3. About SQL
The purpose of SQL is to provide an interface to a
relational database such as Oracle Database,
and all SQL statements are instructions to the
database.
The strengths of SQL provide benefits for all
types of users, including application
programmers, database administrators,
managers, and end users.
4. Why PL/SQL?
How can we have a chain of SQL statements which produce
result according to the output of previous queries?
How can we take any smart decisions based on users input
or based on output on previous queries..?
How can we automate any task using SQL?
5. Introduction
• 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.
• PL/SQL, supplement SQL with standard
programming-language features like:
• Block (modular) structure
• Flow-control statements and loops
• Variables, constants, and types
• Structured data
• Customized error handling
6. Why PL/SQL?
• The purpose of PL/SQL is to combine database
language and procedural programming
language.
• By extending SQL, PL/SQL offers a unique
combination of power and ease of use.
• PL/SQL fully supports all SQL data manipulation
statements.
• We can write procedures and functions which
can be invoked from different applications.
7. PL/SQL Block
• PL/SQL is a block-structured language.
• Each program written in PL/SQL is written as a
block.
• Blocks can also be nested.
• Each block is meant for a particular task.
9. Header Section
Relevant for named blocks only
Stored procedures (used to perform repetitive code.)
Stored functions (used to return value to the calling block),
Packages (allows related objects to be stored together),
Triggers (pl/sql block executed implicitly whenever the
triggering event takes place).
Determines the way that the named block or program
must be called.
Includes the name, parameter list, and RETURN clause (for
a function only).
10. • Header Section: Example
• Below is header section of stored procedure:
CREATE OR REPLACE PROCEDURE
print ( p_num NUMBER ) …
• Below is header section of stored function:
CREATE OR REPLACE FUNCTION
add ( p_num1 NUMBER, p_num2 NUMBER )
RETURN NUMBER …
11. Declare Section
Relevant for anonymous blocks.
Contains declarations of variables, constants,
cursors, user-defined exceptions and types.
Optional section , but if you have one, it must
come before the execution and exception sections.
DECLARE
v_name VARCHAR2(35);
v_id NUMBER := 0;
12. Execution Section
Mandatory section of PLSQL block
Contains SQL statements to manipulate data in the
database
Contains PL/SQL statements to manipulate data in the
block.
Every block must have at least one executable
statement in the execution section.
BEGIN
SELECT ename
INTO v_ename
FROM emp
WHERE empno = 7900 ;
DBMS_OUTPUT.PUT_LINE
(‘Employee name :’ || v_ename);
END;
13. Exception Section
The last section of the PL/SQL block.
It contains statements that are executed when a runtime
error occurs within a block.
An optional section.
Control is transferred to this section when an run time
error is encountered and it is handled
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE
(‘ There is no employee with Employee no 7900 ’);
END;
14. PL/SQL Variables
• These are placeholders that store the values that can change
through the PL/SQL Block
• PL/SQL lets you declare constants and variables, then use
them in SQL and procedural statements anywhere an
expression can be used
• A constant or variable must be declared before referencing it in
other statements
15. Syntax for declaring variables
variable_name [CONSTANT] datatype
[NOT NULL] [:= expr | DEFAULT expr]
Note: Square brace indicates optional
• Variable_name is the name of the variable.
• Datatype is a valid PL/SQL datatype.
• NOT NULL is an optional specification on the
variable.
• A value or DEFAULT value is also an optional
specification, where you can initialize a variable.
• Each variable declaration is a separate statement
and must be terminated by a semicolon.
• CONSTANT keyword is used to declare constants.
17. Guidelines for Declaring PL/SQL
Variables
• Follow the naming Rules
The variable name must be less than 31 characters
The starting of a variable must be an ASCII letter
It can be either lowercase or uppercase
A variable name can contain numbers, underscore, and dollar sign
characters followed by the first character
• Follow the naming conventions
• Initialize variables designated as NOT NULL and CONSTANT
• Declare one identifier per line
• Initialize identifiers by using the assignment operator (:=) or the
reserved word “DEFAULT”
18. Declaring variable of record type :
Example
DECLARE
-- Type declaration
TYPE EmpRec IS RECORD(
empno emp.empno%TYPE,
ename emp.ename%TYPE,
salary emp.sal%TYPE
);
-- Record type variable declaration
V_emp_Rec emprec;
V_emp_Rec
empno number(10)
ename varchar2(25)
salary varchar2(75)
20. Program using variables
DECLARE
X NUMBER(3) := 10;
Y NUMBER(3) := 20;
BEGIN
DBMS_OUTPUT.PUT_LINE
(‘The value of variable X is : ‘ || X);
DBMS_OUTPUT.PUT_LINE
(‘The value of variable Y is : ‘ || Y);
END;
21. Accepting variables from users
DECLARE
v_num1 NUMBER(3):=&n1;
v_num2 NUMBER(3):=&n2;
IS
BEGIN
DBMS_OUTPUT.PUT_LINE
(‘The value of variable v_num1 is : ‘ || v_num1);
DBMS_OUTPUT.PUT_LINE
(‘The value of variable v_num2 is : ‘ || v_num2);
END;
22. PL/SQL Control Structures
• PL/SQL, like other 3GL has a variety of control
structures which include
• Conditional statements
o IF
o CASE
• Loops
o Simple loop
o While loop
o For loop
23. IF .. End if
Syntax
IF condition THEN
Statements;
ELSE
Statements;
END IF;
24. Simple example
-- Block to demonstrate IF...ELSE...END IF
DECLARE
v_empno emp.empno%TYPE;
v_comm emp.comm%TYPE;
BEGIN
SELECT comm INTO v_comm FROM emp
WHERE empno = v_empno;
IF v_comm IS NULL THEN
DBMS_OUTPUT.PUT_LINE
(‘This employee doesnt get commission');
ELSE
DBMS_OUTPUT.PUT_LINE
(‘This employee gets commission’);
END IF;
DBMS_OUTPUT.PUT_LINE
('This line executes irrespective of the condition');
END;
25. PL/SQL Loop Control Structures
LOOP Statements
• Simple Loops
• WHILE Loops
• FOR Loops
26. LOOP Statements
• Simple Loops
Note: Add EXIT statement to exit from the loop
• WHILE Loops
Note: Condition is evaluated before each iteration of the loop
LOOP
Sequence_of_statements;
END LOOP;
WHILE condition
LOOP
Statements;
END LOOP;
27. Loop Example
DECLARE
v_i NUMBER(2) := 1;
BEGIN
LOOP
DBMS_OUTPUT.PUT_LINE(‘Value : ‘|| v_i);
EXIT WHEN v_i = 10;
v_i:=v_i+1;
END LOOP;
END;
28. While loop example
DECLARE
v_i NUMBER(2) := 1;
BEGIN
WHILE ( v_i <= 10 )
LOOP
DBMS_OUTPUT.PUT_LINE(‘Value : ‘|| v_i);
v_i:=v_i+1;
END LOOP;
END;
29. For loop
• The number of iterations for simple loops and WHILE loops is not known in
advance, it depends on the loop condition. Numeric FOR loops, on the
other hand, have defined number of iterations.
Where:
• counter: is an implicitly declared integer whose value
automatically increases or decreases by 1 on each iteration
• REVERSE: causes the counter to decrement from upper
bound to lower bound
• Low_bound: specifies the lower bound for the range of
counter values
• High_bound: specifies the upper bound for the range of
counter values
FOR counter IN [REVERSE] low_bound .. high_bound
LOOP
Statements;
END
30. For Loop example
BEGIN
FOR v_i IN 1..10
/* The LOOP VARIABLE v_i of
type BINARY_INTEGER is declared
automatically */
LOOP
DBMS_OUTPUT.PUT_LINE(‘Value : ‘|| v_i);
END LOOP;
END;
31. For Loop with EXIT condition
DECLARE
myNo NUMBER(5):= &myno;
counter NUMBER(5):=1;
BEGIN
FOR i IN 2..myNo-1
LOOP
counter:= counter+1;
EXIT WHEN myNo mod i = 0;
END LOOP;
IF counter = myNo-1 THEN
DBMS_OUTPUT.PUT_LINE( 'The given
number is prime' );
ELSE
DBMS_OUTPUT.PUT_LINE('The given number is
not
a prime number' );
END IF;
END;
32. Procedures
A Procedure is a subprogram unit that consists of a group of
PL/SQL statements. Each procedure in Oracle has its own
unique name by which it can be referred. This subprogram unit is
stored as a database object. Below are the characteristics of this
subprogram unit.
CREATE OR REPLACE PROCEDURE
<procedure_name>
(
<parameterl IN/OUT <datatype>
)
[ IS | AS ]
<declaration_part>
BEGIN
<execution part>
EXCEPTION
<exception handling part>
END;
33. What is Function
Functions is a standalone PL/SQL subprogram.
Like PL/SQL procedure, functions have a unique
name by which it can be referred. These are
stored as PL/SQL database objects. Below are
some of the characteristics of functions.
CREATE OR REPLACE FUNCTION
<procedure_name>(<parameterl IN/OUT
<datatype>)RETURN <datatype>[ IS | AS
]<declaration_part>BEGIN<execution part>
EXCEPTION<exception handling part>END;
34.
35. Add two numbers
declare
-- declare variable x, y
-- and z of datatype number
x number(5);
y number(5);
z number(7);
begin
-- Here we Assigning 10 into x
x:=10;
-- Assigning 20 into x
y:=20;
-- Assigning sum of x and y into z
z:=x+y;
-- Print the Result
dbms_output.put_line('Sum is '||z);
end;
36. Swapping:
-- declare variable num1, num2
-- and temp of datatype number
num1 number;
num2 number;
temp number;
begin
num1:=1000;
num2:=2000;
-- print result before swapping
dbms_output.put_line('before');
dbms_output.put_line('num1 = '|| num1 ||' num2 = '|| num2);
-- swapping of numbers num1 and num2
temp := num1;
num1 := num2;
num2 := temp;
-- print result after swapping
dbms_output.put_line('after');
dbms_output.put_line('num1 = '|| num1 ||' num2 = '|| num2);
end;
37. Prime Number
declare
-- declare variable n, i
-- and temp of datatype number
n number;
i number;
temp number;
begin
-- Here we Assigning 13 into n
n := 13;
-- Assigning 2 to i
i := 2;
-- Assigning 1 to temp
temp := 1;
38. -- loop from i = 2 to n/2
for i in 2..n/2
loop
if mod(n, i) = 0
then
temp := 0;
exit;
end if;
end loop;
if temp = 1
then
dbms_output.put_line('true');
else
dbms_output.put_line('false');
end if;
end;
-- Program End
39. Fibonocci
declare
-- declare variable first = 0,
-- second = 1 and temp of datatype number
first number := 0;
second number := 1;
temp number;
n number := 5;
i number;
begin
dbms_output.put_line('Series:');
--print first two term first and second
dbms_output.put_line(first);
dbms_output.put_line(second);
-- loop i = 2 to n
for i in 2..n
loop
temp:=first+second;
first := second;
second := temp;
--print terms of fibonacci series
dbms_output.put_line(temp);
end loop;
end;
--Program End
40. Factorial
declare
-- it gives the final answer after computation
fac number :=1;
-- given number n
-- taking input from user
n number := &1;
-- start block
begin
-- start while loop
while n > 0 loop
-- multiple with n and decrease n's value
fac:=n*fac;
n:=n-1;
end loop;
-- end loop
-- print result of fac
dbms_output.put_line(fac);
-- end the begin block
end;
41. Max of two numbers:
1.ECLARE
2. N NUMBER;
3. M NUMBER;
4.BEGIN
5. DBMS_OUTPUT.PUT_LINE('ENTER A
NUMBER');
6. N:=&NUMBER;
7. DBMS_OUTPUT.PUT_LINE('ENTER A
NUMBER');
8. M:=&NUMBER;
9.IF N<M THEN
10. DBMS_OUTPUT.PUT_LINE(''|| N ||' IS
GREATER THAN '|| M ||'');
11.ELSE
12. DBMS_OUTPUT.PUT_LINE(''|| M ||' IS
GREATER THAN '|| N ||'');
13.END IF;
14.END;
15./
43. Even or Odd
DECLARE
-- Declare variable n, s, r, len
-- and m of datatype number
n NUMBER := 1634;
r NUMBER;
BEGIN
-- Calculating modulo
r := MOD(n, 2);
IF r = 0 THEN
dbms_output.Put_line('Even');
ELSE
dbms_output.Put_line('Odd');
END IF;
END;
--End program
44. Leap year
-- To check if a
-- given year is leap year or not
DECLARE
year NUMBER := 1600;
BEGIN
-- true if the year is a multiple
-- of 4 and not multiple of 100.
-- OR year is multiple of 400.
IF MOD(year, 4)=0
AND
MOD(year, 100)!=0
OR
MOD(year, 400)=0 THEN
dbms_output.Put_line(year
|| ' is a leap year ');
ELSE
dbms_output.Put_line(year
|| ' is not a leap year.');
END IF;
END;