SlideShare a Scribd company logo
Unit 3(rdbms)
   Cursors : OPEN CLOSE and FETCH
   Creation of User Defined Function
   Creation of Stored Procedure
 Types of cursor
 Cursor Predicates
 Referencing cursor variable
 Code
   Function : A function is a logical grouped set of
    SQL/PL statement that perform a specific task.

   PL/SQL functions are created by executing the

CREATE FUNCTION statement.

   Such functions can be dropped from the database by
    using the DB2 SQL DROP statement.

     Drop   function Func_name;
Create or replace function function_name (var1
 datatype,var2 datatype) returns datatype

language SQL contains|reads|modifies sql data

Begin

 ………SQL PL code………..

 return <value>;

End;
create or replace function simple_function()

     returns varchar(10)

 begin

             return 'hello';

 end;

 ;
 Create   or replace function bonus(salary
 int, bonus int)

     returns int

     return salary*bonus/100



Example
create or replace function create_table() returns int

language sql modifies sql data

begin

 create table st(id int, name varchar(10), salary
 numeric(10));

  return 0;

end;
 Function   also used to return table.



 Code
 Function_get.txt
 Stored     Procedure is a logical grouped set
  of SQL/PL statement that perform a
  specific task.

 It   can help to improve application
  performance and reduce database access
  traffic.
 Support    procedural construct in high level PL
 like C, c++ and java etc.

 Are   stored in databases and run on DB2
 server.

 Easily   call whenever required(call statement)
 Reduce   network usage between client and server.

 Enhance    capabilities
    Increase memory disk space on the server

 Improve   security
    User can call stored procedure but do not required.

 Reduced    development cost.

 Centralized   security and maintenance.
Create or replace procedure procedure_name

 (in | out | inout arg1 type1,

  in | out | inout arg2 type2,………)

Language SQL contains SQL

Begin

 ……statement…..

End
 Create   procedure name:
    It define name of store procedure.

    What the name and data types of argument.

    In – input variable.

    Out – output variable.

    inout – both input and output.
 Language       SQL contains sql
  Option      can be
        Reads SQL data
        Contains SQL data
        Modifies SQL data

 Begin     ….End statement
    Logic of store procedure

 Code
   Create Procedure p()
   BEGIN DECLARE C1 cursor;
    DECLARE varInt INT;
   SET count = -1;
    SET c1 = CURSOR FOR SELECT c1 FROM t1;
    IF (c1 IS NOT OPEN) THEN OPEN c1;
    ELSE set count = -2; END IF;
   set count = 0;
    IF (c1 IS OPEN) THEN
    FETCH c1 into varInt;
   WHILE (c1 IS FOUND) DO
    SET count = count + 1;
   FETCH c1 INTO varInt;
    END WHILE;
   ELSE SET count = 0;
   END IF;
    END@
 CREATE PROCEDURE
  ADMINISTRATOR.UPDATE_SAL (IN empNum
  CHAR(6), IN rating SMALLINT)

 LANGUAGE   SQL
 BEGIN
 IFrating = 1 THEN
 UPDATE employee
 SET salary = salary * 1.10,
 bonus = 1500 WHERE empno = empNum;
  ELSE UPDATE employee
 SET salary = salary * 1.05, bonus = 1000
  WHERE empno = empNum;
 END IF;
 END

More Related Content

PPT
PL/SQL
PPTX
Procedure n functions
PPTX
Procedure and Functions in pl/sql
PPT
Oracle PL sql 3
PPTX
Function and types
PPTX
Oracle: Procedures
PDF
Programming in Oracle with PL/SQL
PPTX
Unit 3
PL/SQL
Procedure n functions
Procedure and Functions in pl/sql
Oracle PL sql 3
Function and types
Oracle: Procedures
Programming in Oracle with PL/SQL
Unit 3

What's hot (19)

PPT
PPTX
Function & procedure
DOCX
PL/SQL Code for Sample Projects
PPTX
functions of C++
PDF
Packages - PL/SQL
PPTX
User Defined Functions in MATLAB Part-4
PPTX
Function overloading
PPTX
Working with functions in matlab
PPTX
Sql Functions And Procedures
PPTX
Rdbms chapter 1 function
PPTX
Functions in C++
PPT
PPTX
A green solution to solve a race condition problem
PPTX
Function C++
PPTX
Parameter passing to_functions_in_c
PPT
User Defined Functions
PPT
FUNCTIONS IN c++ PPT
PDF
Cpp functions
PPTX
Anonymous and Inline Functions in MATLAB
Function & procedure
PL/SQL Code for Sample Projects
functions of C++
Packages - PL/SQL
User Defined Functions in MATLAB Part-4
Function overloading
Working with functions in matlab
Sql Functions And Procedures
Rdbms chapter 1 function
Functions in C++
A green solution to solve a race condition problem
Function C++
Parameter passing to_functions_in_c
User Defined Functions
FUNCTIONS IN c++ PPT
Cpp functions
Anonymous and Inline Functions in MATLAB
Ad

Viewers also liked (6)

PPTX
Unit 3(rdbms)
DOCX
Assignment 2(web)
PPT
Basic Software Tools for multi-media
PPT
Multimedia software tools
PPT
Multimedia
PPT
Multimedia authoring tools
Unit 3(rdbms)
Assignment 2(web)
Basic Software Tools for multi-media
Multimedia software tools
Multimedia
Multimedia authoring tools
Ad

Similar to Unit 3(rdbms) (20)

PPT
PPT
PPTX
MS SQLSERVER:Sql Functions And Procedures
PPTX
MS SQL SERVER: Sql Functions And Procedures
PPT
L9 l10 server side programming
PPT
Module04
PPT
DAC training-batch -2020(PLSQL)
PDF
PL-SQL.pdf
ODP
MySQL Stored Procedures: Building High Performance Web Applications
PPTX
PLSQLmy Updated (1).pptx
PDF
Lecture Notes Unit5 chapter17 Stored procedures and functions
PPT
Sqlapi0.1
PPTX
PLSQL Tutorial
PPTX
PL/SQL___________________________________
PPTX
Procedures and triggers in SQL
PDF
New features of SQL in Firebird
PDF
Assignment#08
PPT
Less09 Data
PDF
Dynamic websites lec3
PPT
Chapter09
MS SQLSERVER:Sql Functions And Procedures
MS SQL SERVER: Sql Functions And Procedures
L9 l10 server side programming
Module04
DAC training-batch -2020(PLSQL)
PL-SQL.pdf
MySQL Stored Procedures: Building High Performance Web Applications
PLSQLmy Updated (1).pptx
Lecture Notes Unit5 chapter17 Stored procedures and functions
Sqlapi0.1
PLSQL Tutorial
PL/SQL___________________________________
Procedures and triggers in SQL
New features of SQL in Firebird
Assignment#08
Less09 Data
Dynamic websites lec3
Chapter09

More from Jay Patel (20)

DOCX
Quiz(web)
DOCX
Assignment 2(web)
DOCX
Assignment 1(web)
DOCX
I assignmnt(oops)
DOCX
Inline function(oops)
PPTX
1 unit (oops)
PPTX
Unit1
DOCX
Cursor
DOCX
Anchored data type
PPTX
Selection sort
PPT
Mutlimedia authoring tools
PPT
Multimedia software tools
PPT
Lecture6 text
PPT
Sound
PPT
Lecture6 text
PPT
Images
PPT
Hypertext and hypermedia
DOCX
Cursor
DOCX
Codd rules
DOCX
Codd rules
Quiz(web)
Assignment 2(web)
Assignment 1(web)
I assignmnt(oops)
Inline function(oops)
1 unit (oops)
Unit1
Cursor
Anchored data type
Selection sort
Mutlimedia authoring tools
Multimedia software tools
Lecture6 text
Sound
Lecture6 text
Images
Hypertext and hypermedia
Cursor
Codd rules
Codd rules

Recently uploaded (20)

PDF
Modernizing your data center with Dell and AMD
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPT
Teaching material agriculture food technology
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Machine learning based COVID-19 study performance prediction
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Encapsulation theory and applications.pdf
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
Modernizing your data center with Dell and AMD
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Mobile App Security Testing_ A Comprehensive Guide.pdf
Teaching material agriculture food technology
“AI and Expert System Decision Support & Business Intelligence Systems”
Unlocking AI with Model Context Protocol (MCP)
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
NewMind AI Monthly Chronicles - July 2025
Review of recent advances in non-invasive hemoglobin estimation
Digital-Transformation-Roadmap-for-Companies.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Machine learning based COVID-19 study performance prediction
Encapsulation_ Review paper, used for researhc scholars
Advanced methodologies resolving dimensionality complications for autism neur...
Encapsulation theory and applications.pdf
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Chapter 3 Spatial Domain Image Processing.pdf
Per capita expenditure prediction using model stacking based on satellite ima...

Unit 3(rdbms)

  • 2. Cursors : OPEN CLOSE and FETCH  Creation of User Defined Function  Creation of Stored Procedure
  • 3.  Types of cursor  Cursor Predicates  Referencing cursor variable  Code
  • 4. Function : A function is a logical grouped set of SQL/PL statement that perform a specific task.  PL/SQL functions are created by executing the CREATE FUNCTION statement.  Such functions can be dropped from the database by using the DB2 SQL DROP statement.  Drop function Func_name;
  • 5. Create or replace function function_name (var1 datatype,var2 datatype) returns datatype language SQL contains|reads|modifies sql data Begin ………SQL PL code……….. return <value>; End;
  • 6. create or replace function simple_function() returns varchar(10) begin return 'hello'; end; ;
  • 7.  Create or replace function bonus(salary int, bonus int) returns int return salary*bonus/100 Example
  • 8. create or replace function create_table() returns int language sql modifies sql data begin create table st(id int, name varchar(10), salary numeric(10)); return 0; end;
  • 9.  Function also used to return table.  Code  Function_get.txt
  • 10.  Stored Procedure is a logical grouped set of SQL/PL statement that perform a specific task.  It can help to improve application performance and reduce database access traffic.
  • 11.  Support procedural construct in high level PL like C, c++ and java etc.  Are stored in databases and run on DB2 server.  Easily call whenever required(call statement)
  • 12.  Reduce network usage between client and server.  Enhance capabilities  Increase memory disk space on the server  Improve security  User can call stored procedure but do not required.  Reduced development cost.  Centralized security and maintenance.
  • 13. Create or replace procedure procedure_name (in | out | inout arg1 type1, in | out | inout arg2 type2,………) Language SQL contains SQL Begin ……statement….. End
  • 14.  Create procedure name:  It define name of store procedure.  What the name and data types of argument.  In – input variable.  Out – output variable.  inout – both input and output.
  • 15.  Language SQL contains sql  Option can be  Reads SQL data  Contains SQL data  Modifies SQL data  Begin ….End statement  Logic of store procedure  Code
  • 16. Create Procedure p()  BEGIN DECLARE C1 cursor;  DECLARE varInt INT;  SET count = -1;  SET c1 = CURSOR FOR SELECT c1 FROM t1;  IF (c1 IS NOT OPEN) THEN OPEN c1;  ELSE set count = -2; END IF;  set count = 0;  IF (c1 IS OPEN) THEN  FETCH c1 into varInt;  WHILE (c1 IS FOUND) DO  SET count = count + 1;  FETCH c1 INTO varInt;  END WHILE;  ELSE SET count = 0;  END IF;  END@
  • 17.  CREATE PROCEDURE ADMINISTRATOR.UPDATE_SAL (IN empNum CHAR(6), IN rating SMALLINT)  LANGUAGE SQL  BEGIN  IFrating = 1 THEN  UPDATE employee  SET salary = salary * 1.10,  bonus = 1500 WHERE empno = empNum; ELSE UPDATE employee  SET salary = salary * 1.05, bonus = 1000 WHERE empno = empNum;  END IF;  END