SlideShare a Scribd company logo
1 of 17
   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

What's hot

PL/SQL Code for Sample Projects
PL/SQL Code for Sample ProjectsPL/SQL Code for Sample Projects
PL/SQL Code for Sample Projects
jwjablonski
 

What's hot (19)

Plsql
PlsqlPlsql
Plsql
 
Function & procedure
Function & procedureFunction & procedure
Function & procedure
 
PL/SQL Code for Sample Projects
PL/SQL Code for Sample ProjectsPL/SQL Code for Sample Projects
PL/SQL Code for Sample Projects
 
functions of C++
functions of C++functions of C++
functions of C++
 
Packages - PL/SQL
Packages - PL/SQLPackages - PL/SQL
Packages - PL/SQL
 
User Defined Functions in MATLAB Part-4
User Defined Functions in MATLAB Part-4User Defined Functions in MATLAB Part-4
User Defined Functions in MATLAB Part-4
 
Function overloading
Function overloadingFunction overloading
Function overloading
 
Working with functions in matlab
Working with functions in matlabWorking with functions in matlab
Working with functions in matlab
 
Sql Functions And Procedures
Sql Functions And ProceduresSql Functions And Procedures
Sql Functions And Procedures
 
Rdbms chapter 1 function
Rdbms chapter 1 functionRdbms chapter 1 function
Rdbms chapter 1 function
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Plsql
PlsqlPlsql
Plsql
 
A green solution to solve a race condition problem
A green solution to solve a race condition problemA green solution to solve a race condition problem
A green solution to solve a race condition problem
 
Function C++
Function C++ Function C++
Function C++
 
Parameter passing to_functions_in_c
Parameter passing to_functions_in_cParameter passing to_functions_in_c
Parameter passing to_functions_in_c
 
User Defined Functions
User Defined FunctionsUser Defined Functions
User Defined Functions
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
Cpp functions
Cpp functionsCpp functions
Cpp functions
 
Anonymous and Inline Functions in MATLAB
Anonymous and Inline Functions in MATLABAnonymous and Inline Functions in MATLAB
Anonymous and Inline Functions in MATLAB
 

Viewers also liked (6)

Unit 3(rdbms)
Unit 3(rdbms)Unit 3(rdbms)
Unit 3(rdbms)
 
Assignment 2(web)
Assignment 2(web)Assignment 2(web)
Assignment 2(web)
 
Basic Software Tools for multi-media
Basic Software Tools for multi-mediaBasic Software Tools for multi-media
Basic Software Tools for multi-media
 
Multimedia software tools
Multimedia software toolsMultimedia software tools
Multimedia software tools
 
Multimedia
MultimediaMultimedia
Multimedia
 
Multimedia authoring tools
Multimedia authoring toolsMultimedia authoring tools
Multimedia authoring tools
 

Similar to Unit 3(rdbms)

L9 l10 server side programming
L9 l10  server side programmingL9 l10  server side programming
L9 l10 server side programming
Rushdi Shams
 
PLSQLmy Updated (1).pptx
PLSQLmy Updated (1).pptxPLSQLmy Updated (1).pptx
PLSQLmy Updated (1).pptx
vamsiyadav39
 

Similar to Unit 3(rdbms) (20)

SQl
SQlSQl
SQl
 
stored.ppt
stored.pptstored.ppt
stored.ppt
 
MS SQLSERVER:Sql Functions And Procedures
MS SQLSERVER:Sql Functions And ProceduresMS SQLSERVER:Sql Functions And Procedures
MS SQLSERVER:Sql Functions And Procedures
 
MS SQL SERVER: Sql Functions And Procedures
MS SQL SERVER: Sql Functions And ProceduresMS SQL SERVER: Sql Functions And Procedures
MS SQL SERVER: Sql Functions And Procedures
 
L9 l10 server side programming
L9 l10  server side programmingL9 l10  server side programming
L9 l10 server side programming
 
Module04
Module04Module04
Module04
 
DAC training-batch -2020(PLSQL)
DAC training-batch -2020(PLSQL)DAC training-batch -2020(PLSQL)
DAC training-batch -2020(PLSQL)
 
PL-SQL.pdf
PL-SQL.pdfPL-SQL.pdf
PL-SQL.pdf
 
MySQL Stored Procedures: Building High Performance Web Applications
MySQL Stored Procedures: Building High Performance Web ApplicationsMySQL Stored Procedures: Building High Performance Web Applications
MySQL Stored Procedures: Building High Performance Web Applications
 
PLSQLmy Updated (1).pptx
PLSQLmy Updated (1).pptxPLSQLmy Updated (1).pptx
PLSQLmy Updated (1).pptx
 
Sqlapi0.1
Sqlapi0.1Sqlapi0.1
Sqlapi0.1
 
PLSQL Tutorial
PLSQL TutorialPLSQL Tutorial
PLSQL Tutorial
 
Procedures and triggers in SQL
Procedures and triggers in SQLProcedures and triggers in SQL
Procedures and triggers in SQL
 
New features of SQL in Firebird
New features of SQL in FirebirdNew features of SQL in Firebird
New features of SQL in Firebird
 
Assignment#08
Assignment#08Assignment#08
Assignment#08
 
Less09 Data
Less09 DataLess09 Data
Less09 Data
 
Dynamic websites lec3
Dynamic websites lec3Dynamic websites lec3
Dynamic websites lec3
 
Chapter09
Chapter09Chapter09
Chapter09
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
 

More from Jay Patel

Assignment 2(web)
Assignment 2(web)Assignment 2(web)
Assignment 2(web)
Jay Patel
 
Assignment 1(web)
Assignment 1(web)Assignment 1(web)
Assignment 1(web)
Jay Patel
 
I assignmnt(oops)
I assignmnt(oops)I assignmnt(oops)
I assignmnt(oops)
Jay Patel
 
Inline function(oops)
Inline function(oops)Inline function(oops)
Inline function(oops)
Jay Patel
 
1 unit (oops)
1 unit (oops)1 unit (oops)
1 unit (oops)
Jay Patel
 
Anchored data type
Anchored data typeAnchored data type
Anchored data type
Jay Patel
 
Selection sort
Selection sortSelection sort
Selection sort
Jay Patel
 
Mutlimedia authoring tools
Mutlimedia authoring toolsMutlimedia authoring tools
Mutlimedia authoring tools
Jay Patel
 
Multimedia software tools
Multimedia software toolsMultimedia software tools
Multimedia software tools
Jay Patel
 
Lecture6 text
Lecture6   textLecture6   text
Lecture6 text
Jay Patel
 
Lecture6 text
Lecture6   textLecture6   text
Lecture6 text
Jay Patel
 
Hypertext and hypermedia
Hypertext and hypermediaHypertext and hypermedia
Hypertext and hypermedia
Jay Patel
 

More from Jay Patel (20)

Quiz(web)
Quiz(web)Quiz(web)
Quiz(web)
 
Assignment 2(web)
Assignment 2(web)Assignment 2(web)
Assignment 2(web)
 
Assignment 1(web)
Assignment 1(web)Assignment 1(web)
Assignment 1(web)
 
I assignmnt(oops)
I assignmnt(oops)I assignmnt(oops)
I assignmnt(oops)
 
Inline function(oops)
Inline function(oops)Inline function(oops)
Inline function(oops)
 
1 unit (oops)
1 unit (oops)1 unit (oops)
1 unit (oops)
 
Unit1
Unit1Unit1
Unit1
 
Cursor
CursorCursor
Cursor
 
Anchored data type
Anchored data typeAnchored data type
Anchored data type
 
Selection sort
Selection sortSelection sort
Selection sort
 
Mutlimedia authoring tools
Mutlimedia authoring toolsMutlimedia authoring tools
Mutlimedia authoring tools
 
Multimedia software tools
Multimedia software toolsMultimedia software tools
Multimedia software tools
 
Lecture6 text
Lecture6   textLecture6   text
Lecture6 text
 
Sound
SoundSound
Sound
 
Lecture6 text
Lecture6   textLecture6   text
Lecture6 text
 
Images
ImagesImages
Images
 
Hypertext and hypermedia
Hypertext and hypermediaHypertext and hypermedia
Hypertext and hypermedia
 
Cursor
CursorCursor
Cursor
 
Codd rules
Codd rulesCodd rules
Codd rules
 
Codd rules
Codd rulesCodd rules
Codd rules
 

Recently uploaded

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

Unit 3(rdbms)

  • 1.
  • 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