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

Function & procedure
Function & procedureFunction & procedure
Function & procedureatishupadhyay
 
PL/SQL Code for Sample Projects
PL/SQL Code for Sample ProjectsPL/SQL Code for Sample Projects
PL/SQL Code for Sample Projectsjwjablonski
 
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-4Shameer Ahmed Koya
 
Working with functions in matlab
Working with functions in matlabWorking with functions in matlab
Working with functions in matlabharman kaur
 
Rdbms chapter 1 function
Rdbms chapter 1 functionRdbms chapter 1 function
Rdbms chapter 1 functiondipumaliy
 
Functions in C++
Functions in C++Functions in C++
Functions in C++home
 
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 problemKai Zhou
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT03062679929
 
Anonymous and Inline Functions in MATLAB
Anonymous and Inline Functions in MATLABAnonymous and Inline Functions in MATLAB
Anonymous and Inline Functions in MATLABShameer Ahmed Koya
 

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

Unit 3(rdbms)
Unit 3(rdbms)Unit 3(rdbms)
Unit 3(rdbms)Jay Patel
 
Assignment 2(web)
Assignment 2(web)Assignment 2(web)
Assignment 2(web)Jay Patel
 
Basic Software Tools for multi-media
Basic Software Tools for multi-mediaBasic Software Tools for multi-media
Basic Software Tools for multi-mediaguestb7a19c
 
Multimedia software tools
Multimedia software toolsMultimedia software tools
Multimedia software toolsJay Patel
 
Multimedia authoring tools
Multimedia authoring toolsMultimedia authoring tools
Multimedia authoring toolsOnline
 

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)

MS SQLSERVER:Sql Functions And Procedures
MS SQLSERVER:Sql Functions And ProceduresMS SQLSERVER:Sql Functions And Procedures
MS SQLSERVER:Sql Functions And Proceduressqlserver content
 
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 Proceduressqlserver content
 
L9 l10 server side programming
L9 l10  server side programmingL9 l10  server side programming
L9 l10 server side programmingRushdi Shams
 
DAC training-batch -2020(PLSQL)
DAC training-batch -2020(PLSQL)DAC training-batch -2020(PLSQL)
DAC training-batch -2020(PLSQL)RajKumarSingh213
 
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 ApplicationsOSSCube
 
PLSQLmy Updated (1).pptx
PLSQLmy Updated (1).pptxPLSQLmy Updated (1).pptx
PLSQLmy Updated (1).pptxvamsiyadav39
 
Procedures and triggers in SQL
Procedures and triggers in SQLProcedures and triggers in SQL
Procedures and triggers in SQLVikash Sharma
 
New features of SQL in Firebird
New features of SQL in FirebirdNew features of SQL in Firebird
New features of SQL in FirebirdMind The Firebird
 
Dynamic websites lec3
Dynamic websites lec3Dynamic websites lec3
Dynamic websites lec3Belal Arfa
 
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...Alex Zaballa
 
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...Alex Zaballa
 

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 typeJay Patel
 
Selection sort
Selection sortSelection sort
Selection sortJay Patel
 
Mutlimedia authoring tools
Mutlimedia authoring toolsMutlimedia authoring tools
Mutlimedia authoring toolsJay Patel
 
Multimedia software tools
Multimedia software toolsMultimedia software tools
Multimedia software toolsJay Patel
 
Lecture6 text
Lecture6   textLecture6   text
Lecture6 textJay Patel
 
Lecture6 text
Lecture6   textLecture6   text
Lecture6 textJay Patel
 
Hypertext and hypermedia
Hypertext and hypermediaHypertext and hypermedia
Hypertext and hypermediaJay 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

"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Visualising and forecasting stocks using Dash
Visualising and forecasting stocks using DashVisualising and forecasting stocks using Dash
Visualising and forecasting stocks using Dashnarutouzumaki53779
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 

Recently uploaded (20)

"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Visualising and forecasting stocks using Dash
Visualising and forecasting stocks using DashVisualising and forecasting stocks using Dash
Visualising and forecasting stocks using Dash
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 

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