PL/SQL is a combination of SQL along with procedural programming features. It allows developers to perform operations on data in an Oracle database such as querying, inserting, updating, and deleting. Some key PL/SQL concepts include variables, conditions, loops, exceptions, triggers, stored procedures, and cursors. Cursors allow a program to retrieve multiple rows from a SQL statement and process them one by one.
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.
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.
This presentation is on SQL constraints. This presentation was used by me in my YouTube vlog on SQL constraints. Vlog link: https://youtu.be/E94YFmATqb4
Consists of the explanations of the basics of SQL and commands of SQL.Helpful for II PU NCERT students and also degree studeents to understand some basic things.
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.
Using and Creating SQL Functions with Ammar Hassan Brohi.
String Functions
Numeric Functions
String / Number Conversion Functions
Group Functions
Date and Time Functions
Date Conversion Functions
This presentation is on SQL constraints. This presentation was used by me in my YouTube vlog on SQL constraints. Vlog link: https://youtu.be/E94YFmATqb4
Consists of the explanations of the basics of SQL and commands of SQL.Helpful for II PU NCERT students and also degree studeents to understand some basic things.
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.
Using and Creating SQL Functions with Ammar Hassan Brohi.
String Functions
Numeric Functions
String / Number Conversion Functions
Group Functions
Date and Time Functions
Date Conversion Functions
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.
A tale of scale & speed: How the US Navy is enabling software delivery from l...sonjaschweigert1
Rapid and secure feature delivery is a goal across every application team and every branch of the DoD. The Navy’s DevSecOps platform, Party Barge, has achieved:
- Reduction in onboarding time from 5 weeks to 1 day
- Improved developer experience and productivity through actionable findings and reduction of false positives
- Maintenance of superior security standards and inherent policy enforcement with Authorization to Operate (ATO)
Development teams can ship efficiently and ensure applications are cyber ready for Navy Authorizing Officials (AOs). In this webinar, Sigma Defense and Anchore will give attendees a look behind the scenes and demo secure pipeline automation and security artifacts that speed up application ATO and time to production.
We will cover:
- How to remove silos in DevSecOps
- How to build efficient development pipeline roles and component templates
- How to deliver security artifacts that matter for ATO’s (SBOMs, vulnerability reports, and policy evidence)
- How to streamline operations with automated policy checks on container images
Sudheer Mechineni, Head of Application Frameworks, Standard Chartered Bank
Discover how Standard Chartered Bank harnessed the power of Neo4j to transform complex data access challenges into a dynamic, scalable graph database solution. This keynote will cover their journey from initial adoption to deploying a fully automated, enterprise-grade causal cluster, highlighting key strategies for modelling organisational changes and ensuring robust disaster recovery. Learn how these innovations have not only enhanced Standard Chartered Bank’s data infrastructure but also positioned them as pioneers in the banking sector’s adoption of graph technology.
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...Neo4j
Leonard Jayamohan, Partner & Generative AI Lead, Deloitte
This keynote will reveal how Deloitte leverages Neo4j’s graph power for groundbreaking digital twin solutions, achieving a staggering 100x performance boost. Discover the essential role knowledge graphs play in successful generative AI implementations. Plus, get an exclusive look at an innovative Neo4j + Generative AI solution Deloitte is developing in-house.
Pushing the limits of ePRTC: 100ns holdover for 100 daysAdtran
At WSTS 2024, Alon Stern explored the topic of parametric holdover and explained how recent research findings can be implemented in real-world PNT networks to achieve 100 nanoseconds of accuracy for up to 100 days.
GraphRAG is All You need? LLM & Knowledge GraphGuy Korland
Guy Korland, CEO and Co-founder of FalkorDB, will review two articles on the integration of language models with knowledge graphs.
1. Unifying Large Language Models and Knowledge Graphs: A Roadmap.
https://arxiv.org/abs/2306.08302
2. Microsoft Research's GraphRAG paper and a review paper on various uses of knowledge graphs:
https://www.microsoft.com/en-us/research/blog/graphrag-unlocking-llm-discovery-on-narrative-private-data/
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...James Anderson
Effective Application Security in Software Delivery lifecycle using Deployment Firewall and DBOM
The modern software delivery process (or the CI/CD process) includes many tools, distributed teams, open-source code, and cloud platforms. Constant focus on speed to release software to market, along with the traditional slow and manual security checks has caused gaps in continuous security as an important piece in the software supply chain. Today organizations feel more susceptible to external and internal cyber threats due to the vast attack surface in their applications supply chain and the lack of end-to-end governance and risk management.
The software team must secure its software delivery process to avoid vulnerability and security breaches. This needs to be achieved with existing tool chains and without extensive rework of the delivery processes. This talk will present strategies and techniques for providing visibility into the true risk of the existing vulnerabilities, preventing the introduction of security issues in the software, resolving vulnerabilities in production environments quickly, and capturing the deployment bill of materials (DBOM).
Speakers:
Bob Boule
Robert Boule is a technology enthusiast with PASSION for technology and making things work along with a knack for helping others understand how things work. He comes with around 20 years of solution engineering experience in application security, software continuous delivery, and SaaS platforms. He is known for his dynamic presentations in CI/CD and application security integrated in software delivery lifecycle.
Gopinath Rebala
Gopinath Rebala is the CTO of OpsMx, where he has overall responsibility for the machine learning and data processing architectures for Secure Software Delivery. Gopi also has a strong connection with our customers, leading design and architecture for strategic implementations. Gopi is a frequent speaker and well-known leader in continuous delivery and integrating security into software delivery.
Communications Mining Series - Zero to Hero - Session 1DianaGray10
This session provides introduction to UiPath Communication Mining, importance and platform overview. You will acquire a good understand of the phases in Communication Mining as we go over the platform with you. Topics covered:
• Communication Mining Overview
• Why is it important?
• How can it help today’s business and the benefits
• Phases in Communication Mining
• Demo on Platform overview
• Q/A
Essentials of Automations: The Art of Triggers and Actions in FMESafe Software
In this second installment of our Essentials of Automations webinar series, we’ll explore the landscape of triggers and actions, guiding you through the nuances of authoring and adapting workspaces for seamless automations. Gain an understanding of the full spectrum of triggers and actions available in FME, empowering you to enhance your workspaces for efficient automation.
We’ll kick things off by showcasing the most commonly used event-based triggers, introducing you to various automation workflows like manual triggers, schedules, directory watchers, and more. Plus, see how these elements play out in real scenarios.
Whether you’re tweaking your current setup or building from the ground up, this session will arm you with the tools and insights needed to transform your FME usage into a powerhouse of productivity. Join us to discover effective strategies that simplify complex processes, enhancing your productivity and transforming your data management practices with FME. Let’s turn complexity into clarity and make your workspaces work wonders!
The Art of the Pitch: WordPress Relationships and SalesLaura Byrne
Clients don’t know what they don’t know. What web solutions are right for them? How does WordPress come into the picture? How do you make sure you understand scope and timeline? What do you do if sometime changes?
All these questions and more will be explored as we talk about matching clients’ needs with what your agency offers without pulling teeth or pulling your hair out. Practical tips, and strategies for successful relationship building that leads to closing the deal.
UiPath Test Automation using UiPath Test Suite series, part 5DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 5. In this session, we will cover CI/CD with devops.
Topics covered:
CI/CD with in UiPath
End-to-end overview of CI/CD pipeline with Azure devops
Speaker:
Lyndsey Byblow, Test Suite Sales Engineer @ UiPath, Inc.
GridMate - End to end testing is a critical piece to ensure quality and avoid...ThomasParaiso2
End to end testing is a critical piece to ensure quality and avoid regressions. In this session, we share our journey building an E2E testing pipeline for GridMate components (LWC and Aura) using Cypress, JSForce, FakerJS…
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...DanBrown980551
Do you want to learn how to model and simulate an electrical network from scratch in under an hour?
Then welcome to this PowSyBl workshop, hosted by Rte, the French Transmission System Operator (TSO)!
During the webinar, you will discover the PowSyBl ecosystem as well as handle and study an electrical network through an interactive Python notebook.
PowSyBl is an open source project hosted by LF Energy, which offers a comprehensive set of features for electrical grid modelling and simulation. Among other advanced features, PowSyBl provides:
- A fully editable and extendable library for grid component modelling;
- Visualization tools to display your network;
- Grid simulation tools, such as power flows, security analyses (with or without remedial actions) and sensitivity analyses;
The framework is mostly written in Java, with a Python binding so that Python developers can access PowSyBl functionalities as well.
What you will learn during the webinar:
- For beginners: discover PowSyBl's functionalities through a quick general presentation and the notebook, without needing any expert coding skills;
- For advanced developers: master the skills to efficiently apply PowSyBl functionalities to your real-world scenarios.
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
ORACLE PL SQL FOR BEGINNERS
1. PL/SQL
PL/SQL stands for Procedural Language
extension of SQL.
By
MOHD MIRZA
OCP(Oracle Certified Professional)
1
2. PL/SQL is a combination of SQL along with the
procedural features of programming languages.
Properties of
programming as well
as the great
interaction with
database.
PLSQL IS NOT A CASE
SENSITIVE LANG.
2
4. WHERE AND HOW TO RUN ORACLE
PL/SQL IN WINDOWS ?
• YOU HAVE ORACLE 9i/10g/11g in your system.
• THEN FOLLOWS THESE STEPS
• 1) OPEN RUN PROMPT
• 2)TPYE SQLPLUS/NOLOG
• 3)TYPE CONNECT AND THEN ENTER
• USERNAME :HR
• PASSWORD:HR
4
8. IMPORTANT PL SQL CONCEPTS
DECLARE :- if you want to decalre a variable in
plsql program then it takes place in declare
section
BEGIN:- is used to start the working of program
and end is used to terminate the begin.
Delimiter is used to run (/)
8
9. WHAT TO DO PREVIOUSLY
• SET SERVEROUTPUT ON ; is run before every
time when you compiled a program in a
session.
• SET ECHO ON ; is optional
91
10. FOR PRINT ON YOUR SCREEN USE
• DBMS_OUTPUT.PUT_LINE command for e.g. if
sal=10 and you want to print it
• Then it looks like
• dbms_output.put_line(‘the salary is ‘ ||sal);
10
11. Value assign in variable
Declare
Num number(11);
Begin
Num:=5;
11
12. User’s input for a variable
DECALRE
N NUMBER(11);
BEGIN
N:=&N;
DBMS_OUTPUT.PUT_LINE(‘THE VALUE IS ‘||N);
END;
/
12
13. Sample program to print your ‘hello
world’
BEGIN
Dbms_output.put_line(‘hello world’);
End;
/
/ is used to terminate plsql program called as
delimeter
13
14. IF STATEMENT
IF STATEMENT WORKS AS SIMILAR AS C OR C++
Common syntax
IF condition THEN
statement 1;
ELSE
statement 2;
END IF;
14
15. Conditional statement IF then else
• DECLARE
• Age number(11);
• Begin
• Age:=&age;
• If age>18 then
• Dbms_output.put_line(‘u can vote’);
• Else
• Dbms_output.put_line(‘u cannot vote’);
• End if;
• End;
• /
15
16. USE OF IF WITH SQL TABLE
• Declare
• A number(11);
• Begin
• Select salary into a from emp where name=‘ram’;
• If a>1000 then
• Update emp set bonus=bonus+1000 where name=‘ram’;
• Else
• Update emp set bonus=bonus+500 where name=‘ram’;
• End if;
• End;
• /
16
17. To print Pat salary from employees
table using pl program
• Declare
• n number(11);
• Begin
• Select salary into n from employees where
first_name=‘Pat’;
• Dbms_output.put_line(‘the Pat sal is ‘ ||n);
• End;
• /
17
18. INTO COMMAND
I
INTO command is used to catch a value in variable
from table under some while condition
Only one value must be returned
For e.g. in the above example if there are two
people who’s name is john then it shows error
18
20. FOR LOOP
• Print number from 1 to 10 using for loop
• BEGIN
• FOR i in 1 ..10 loop
• Dbms_output.put_line(i);
• End loop
• End;
• /
• (For has NO need to initialize explicitly but it need
in while )
20
21. While loop
• PRINT NUMBERS FROM 1 TO 10 USING WHILE LOOP
• Declare
• i number(3):=0;
• Begin
• While i<=10 loop
• i:=i+1;
• Dbms_output.put_line(i);
• End loop;
• End;
• /
21
23. USE OF LOOP IN RDBMS
ONE CAN EASILY INSERT ID FROM SAY 1 TO
100 USING LOOP
NAME ID SAL
23
24. CREATE TRIGGERS
• A trigger is a pl/sql block structure which is
fired when a DML statements like
Insert, Delete, Update is executed on a
database table. A trigger is triggered
automatically when an associated DML
statement is executed.
24
25. Insert Triggers:
BEFORE INSERT Trigger
AFTER INSERT Trigger
Update Triggers:
BEFORE UPDATE Trigger
AFTER UPDATE Trigger
Delete Triggers:
BEFORE DELETE Trigger
AFTER DELETE Trigger
Drop Triggers:
Drop a Trigger
Disable/Enable Triggers:
Disable a Trigger
Disable all Triggers on a table
Enable a Trigger
Enable all Triggers on a table
25
31. • If qty from product table fall within 100 then
automatically an order of that product is
placed in order table.
31
32.
• Create trigger abcd
• After update of qty on product
• For each row
• When(new.qty<100)
• Begin
• Insert into order values(:new.pid);
• End;
• /
32
33. EXCEPTION HANDLING
WHAT IS EXCEPTION …?
• AN EXCEPTION IS AN ERROR PL/SQL THAT IS
RAISED DURING PROGRAM EXECUTION
• AN EXCEPTION CAN BE RAISED BY
• 1) IMPLICITLY BY THE ORACLE SERVER
• 2) Explicitly by the program
33
34. Type of Exception
• There are 3 types of Exceptions.
a) Named System Exceptions
b) Unnamed System Exceptions
c) User-defined Exceptions
34
35. 1) Named System Exceptions
• System exceptions are automatically raised by
Oracle, when a program violates a RDBMS
rule.
• For e.g.
• 1)CURSOR_ALREADY_OPEN
• 2)NO_DATA_FOUND
• 3)TOO_MANY_ROWS
• 4)ZERO_DIVIDE
35
36. TOO_MANY_ROWS
EXAMPLE
• SUPPOSE YOU WANT TO RETRIEVE ALL
EMPLOYEES WHOSE NAME=‘JOHN’
• DECLARE
• a varchar(12)
• SELECT LAST_NAME into a from employees
where first_name=‘john’
• Dbms_output.put_line(‘john last name is ‘ ||a);
• End;
• /
36
37. But if too many people have first_name=‘john’ then
using exception handling
• DECLARE
• a varchar(12)
• SELECT LAST_NAME into a from employees where
first_name=‘john’
• Dbms_output.put_line(‘john last name is ‘ ||a);
• End;
• /
• Exception
• When too_many_rows then
• Dbms_output.put_line(‘your st. gets many rows ‘);
• End;
• /
37
38. 2)Unnamed System Exceptions
• Those system exception for which oracle does
not provide a name is known as unamed
system exception
• There are two ways to handle unnamed
sysyem exceptions:
1. By using the WHEN OTHERS exception
handler, or
2. By associating the exception code to a
name and using it as a named exception
38
39. Unnamed System Exceptions CONT..
• We can assign a name to unnamed system
exceptions using a Pragma called
EXCEPTION_INIT.
EXCEPTION_INIT will associate a predefined
Oracle error number to a
programmer_defined exception name.
39
40. FOR E.G.
• DECLARE
• AAA EXCEPTION; -------AAA IS EXCEPTION NAME
• PRAGMA --------------------USE TO DEFINE UNMANED EXCEPTION
• EXCEPTION_INIT (AAA, -2292); -------------------------MUST BE VALID EXCEPTION NUMBER
• BEGIN
• Delete FROM SUPPLIER where SUPPLIER_ID= 1;
• EXCEPTION
• WHEN AAA
• THEN Dbms_output.put_line(' $$Child records are present for this product_id.');
• END;
• /
40
41. WHAT HAPPENS IN PREVIOUS
EXAMPLE
• IF U WANT TO DELETE SUPPLIER_ID=1 THEN
AN EXCEPTION OCCURS WHICH WILL PRINT AS
WHICH IS IN DBMS_OUTPUT.
• ACTUALLY THIS ECEPTION WORKS ON PARENT
CHILD DELETION AND THE ERROR NUMBER
SIGNIFIES THE TYPE OF ERR AND FOR USER
EASE WE MAKE A USEFUL OR
UNDERSTANDABLE PRINT STATEMENT
41
42. 3) User-defined Exceptions
• Apart from sytem exceptions we can explicity define
exceptions based on business rules. These are known
as user-defined exceptions.
• DECLARE
• my-exception EXCEPTION;
• ----
• ----
• Raise name_of_exception;
42
43. FOR E.G.
• DECLARE
• ----
• Zero_commission Exception;
• BEGIN
• IF commission=0 THEN
• RAISE zero_commission
• EXCEPTION
• WHEN zero_commission THEN
• Process the error
• END;
43
44. For example
When the user enters an invalid ID, the exception
invalid_id is raised
• DECLARE
• c_id customers.id%type := &cc_id;-------------input id at run time
• c_name customers.name%type; --------------c_name variable as same datatype
• c_addr customers.address%type; as customer name datatype
• -- user defined exception
• ex_invalid_id EXCEPTION;------------exception name
• BEGIN
• IF c_id <= 0 THEN
• RAISE ex_invalid_id;----------------raise user condition
• ELSE
• SELECT name, address INTO c_name, c_addr
• FROM customers
• WHERE id = c_id;
44
45. • DBMS_OUTPUT.PUT_LINE ('Name: '|| c_name);
• DBMS_OUTPUT.PUT_LINE ('Address: ' || c_addr);
• END IF;
• EXCEPTION
• WHEN ex_invalid_id THEN -------user exception
• dbms_output.put_line('ID must be greater than zero!');
• WHEN no_data_found THEN -------predefined exception
• dbms_output.put_line('No such customer!');
• WHEN others THEN--------------------predefined exception
• dbms_output.put_line('Error!');
• END;
• /
45
46. STORED PROCEDURE
• SOMETHING LIKE FUNCIONS IN C/C++.
• A stored procedure is a subroutine available to
applications that access a relational database
system. A stored procedure (sometimes
called a proc, sproc, StoPro, StoredProc, sp
or SP) is actually stored in the database data
dictionary.
• A procedure is similar to an anonymous
PL/SQL Block but it is named for repeated usage.
A procedure may or may not return any value
46
47. Common syntax
• CREATE [OR REPLACE] PROCEDURE
procedure_name
• [ (parameter [,parameter]) ]
• IS
• [declaration_section]
• BEGIN
• executable_section
• [EXCEPTION exception_section]
• END [procedure_name];
47
48. EXAMPLE WITHOUT PARAMETER
• CREATE OR REPLACE PROCEDURE MYSTPROC
IS
• BEGIN
• DBMS_OUTPUT.PUT_LINE('Hello World!');
• END;
• /
48
49. When you create a procedure or
function, you may define
parameters. There are three types
of parameters that can be declared
49
50. PARAMETER TYPES
• 1) IN type parameter: These types of
parameters are used to send values to stored
procedures.
2) OUT type parameter: These types of
parameters are used to get values from stored
procedures. This is similar to a return type in
functions.
3) IN OUT parameter: These types of
parameters are used to send values and get
values from stored procedures.
50
51. 1) IN PARAMETER
This is similar to passing parameters in programming
languages. We can pass values to the stored procedure
through these parameters or variables.
CREATE OR REPLACE PROCEDURE MYPROC(param1 IN
VARCHAR2)
IS
BEGIN
DBMS_OUTPUT.PUT_LINE('Hello World IN parameter '
|| param1);
END;
/
51
52. 2) OUT Parameter
• CREATE OR REPLACE PROCEDURE procname (outParam1 OUT
VARCHAR2)
• IS
• BEGIN
• outParam1 := 'Hello World OUT parameter';
• END;
• /
• Run it
• DECLARE outParam1 VARCHAR2(100);
• BEGIN
• Procname (outParam1);
• DBMS_OUTPUT.PUT_LINE(outParam1);
• END;
• /
52
53. DIFF B/W PROCEDURE AND FUNCTION
• The functions can return only one value and
procedures not. Functions can be call from
SQL Statements, procedures not and there are
some things that you can
do in a stored procedure that you can not do
in a function.
53
54. FOR E.G.
• Create a stored procedure that adds 1000 to
each employees commission watch for Null
values
• Create procedure st_proc as
• Begin
• Update emp set comm=nvl(comm,0)+1000;
• End;
• /
54
55. Procedure can call at any time using
• Execute st_proc; ------- procedure name
• OR
• Exec st_proc;---------------procedure name
55
56. FUNCTIONS
• A function is a named PL/SQL Block which is
similar to a procedure. The major difference
between a procedure and a function is, a
function must always return a value, but a
procedure may or may not return a value.
56
57. FUNCTION EXAMPLE
• Create function funname
• Return number is
• a number(10);
• Begin
• Select avg(sal) into a from emp;
• return a;
• End;
• /
57
58. HOW TO EXECUTE FUNCTION ?
1) SELECT FUNCTIONNAME FROM DUAL;
2)DBMS_OUTPUT.PUT_LINE(FUNCTIONNAME);
58
59. CURSORS
• A cursor is a temporary work area created in the
system memory when a SQL statement is
executed. A cursor contains information on a
select statement and the rows of data accessed
by it.
• Cursors provide a way for your program to select
multiple rows of data from the database and then
to process each row individually.
• There are two types of cursors in PL/SQL:
• 1)IMPLICIT CURSORS
• 2) Explicit cursors
59
60. A CURSOR CAN HOLD MORE
THAN ONE ROW, BUT CAN
PROCESS ONLY ONE ROW AT A
TIME.
60
61. Implicit Cursors
• These are created by default when DML statements
like, INSERT, UPDATE, and DELETE statements are
executed.
• The set of rows returned by query is called active set.
• Oracle provides few attributes called as implicit cursor
attributes to check the status of DML operations. The
are as follows
• 1) %FOUND
• 2) %NOTFOUND
• 3) %ROWCOUNT
• 4) %ISOPEN.
61
62. FOR E.G.
DECLARE
• n number(5);
• BEGIN
• UPDATE emp SET salary = salary + 1000;
• IF SQL%NOTFOUND THEN
• dbms_output.put_line('No sal are updated');
• ELSIF SQL%FOUND THEN
• n := SQL%ROWCOUNT;
• dbms_output.put_line('Sal for ' ||n || 'employees are
updated');
• END IF;
• END;
• /
62
63. EXPLANATION
• %FOUND->The return value is TRUE, if the
DML statements like INSERT, DELETE and
UPDATE affect at least one row and if SELECT
….INTO statement return at least one row.
• %NOTFOUND->same as above but if not
found.
• %ROWCOUNT ->Return the number of rows
affected by the DML operations
63
64. Explicit Cursors
• Explicit cursors are declared by and used by
user to process multiple rows ,returned by
select statement.
• An explicit cursor is defined in the declaration
section of the PL/SQL Block. It is created on a
SELECT Statement which returns more than
one row. We can provide a suitable name for
the cursor.
64
65. Explicit cursor management
• 1)Declare the cursor
• 2)Open the cursor
• 3)Fetch data from cursor
• 4)Close the cursor
65
66. Declaring the cursor
• CURSOR cursor_name IS select_statement;
• For e.g.
• Cursor cursor_name is
• Select name from emp where dept=‘maths’
66
67. Opening the cursor
• Open cursor_name
• For e.g.
• Open c_name
• Where c_name is the name of cursor.
• Open statement retrieves the records from db
and places in the cursor(private sql area).
67
68. Fetching data from cursor
• The fetch statement retrieves the rows from the active
set one row at a time. The fetch statement is used
usually used in conjunction with iterative process
(looping statements)
• Syntax: FETCH cursor-name INTO record-list
• Ex: LOOP
• -----------
• ------------
• FETCH c_name INTO name;
• -----------
• END LOOP;
68
69. Closing a cursor:
• Closing statement closes/deactivates/disables
the previously opened cursor and makes the
active set undefined.
• Syntax : CLOSE cursor_name
69
70. Cursor can store multiple rows at a
time but without loop cursor
cannot fetch multiple rows but
only print very first row from your
result e.g. on next slide
70
71. Without loop example
• declare
• a emp%rowtype;
• cursor cc is ------------cursor name
• select * from emp where sal>1000;
• begin
• open cc;-------------------------------open cursor
• fetch cc into a;------------------------------fetch cursor
• dbsm_output.put_line(a.ename || a.job);--print multiple rows
• close cc;
• end;
• /
• output:-allen salesman
71
72. USING LOOP FOR FETCHING MULTIPLE
ROWS THROUGH CURSORS
• declare
• cursor qaz is
• select ename,job from emp;
• a qaz%rowtype;------------------a of cursor type variable
• begin
• open qaz;----------------------open cursor
• loop
• fetch qaz into a;-----------------fetch cursor
• exit when qaz%notfound;-------------exit when not found
• dbms_output.put_line(a.ename || a.job);
• end loop;
• end;
• /
72
73. Another Cursor example (not
necessary)
• The HRD manager has decided to raise the
salary for all the employees in the physics
department by 0.05 whenever any such raise
is given to the employees, a record for the
same is maintained in the emp_raise table (
the data table definitions are given below ).
Write a PL/SQL block to update the salary of
each employee and insert the record in the
emp_raise table.
73
75. • DECLARE
• CURSOR c_emp IS -------------------cursor name
• SELECT emp_code, salary FROM employee----query which stored in cursor
• WHERE dept = 'physics';
• a employee.emp_code %TYPE;-------variable declare
• b employee.salary %TYPE;
• BEGIN
• OPEN c_emp;--------------------open cursor
• LOOP---------------------------------fetching records using loop
• FETCH c_emp INTO a, b;----- fetching records and stored in
• UPDATE employee SET salary : = b + (b* 0.05)
• WHERE emp_code = str_e;
• INSERT INTO emp_raise
• VALUES ( str_emp_code, sysdate, num_salary * 0.05 );
• END LOOP;
• Commit;
• CLOSE c_emp;
• END;
75
76. PACKAGES
• A Package is a container that may have many
functions and procedures within it.
• A PACKAGE is a group of programmatic
constructs combined.
• A package is a schema object that groups
logically related PL/SQL types, items, and
subprograms
76
77. A PACKAGE EXISTS IN TWO PARTS:
• Package Specification:- The specification is
the interface to your applications it declares
the
types, variables, constants, exceptions, cursors
, and subprograms available for use. Package
Body:-This contains the definition of the
constructs prototyped in the spec. It may also
contain the private or locally defined program
units, which can be used within the scope of
the package body only.. 77
79. SIMPLE EXAMPLE ON
PACKAGE
• STEP NO 1:- Package specification created first
means the definition of constructs in pacakage
CREATE OR REPLACE PACKAGE PKG_NAME IS
PROCEDURE P_ENAME(P_VAR VARCHAR2);
END;
/
79
80. STEP NO 2 ) Creating package body
• CREATE OR REPLACE PACKAGE BODY
PKGNAME IS
PROCEDURE P_ENAME(P_VAR VARCHAR2) IS
BEGIN
DBMS_OUTPUT.PUT_LINE(P_VAR);
END;
END PKGNAME;PACKAGE END
/
80
81. CALLING PACAKGE
• EXECUTE IS USED TO CALL A PACAKAGE
• EXEC PKG_UTIL.P_ENAME(‘MIRZA');
• OUTPUT:-MIRZA
81