SlideShare une entreprise Scribd logo
1  sur  19
UNIT : 3
APPLICATION DEVELOPMENT
 USING PROCEDURAL SQL



             Prepared By : Preeti Bhatt
Content :

    Cursors : OPEN CLOSE and FETCH

    Creation of User Defined Function

    Creation of Stored Procedure
Cursor
   code
Creating User Defined Function

   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;
Syntax

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;
Example(simple)

create or replace function simple_function()
  returns varchar(10)
  begin
           return 'hello';
  end;
  ;
Example

   Create or replace function bonus(salary int, bonus
    int)

           returns int

           return salary*bonus/100

Example
Example ( modifies data)

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;
Return Table
   Function also used to return table.

   code
Stored Procedure

   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.

   Procedure does not return any value.
Characteristics :

   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)
Benefits of SP

   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 direct
        access to the content of the database .
   Reduced development cost.
   Centralized security and maintenance.
Structure of SP

Create or replace procedure procedure_name
  (in | out | inout arg1 type1,
  in | out | inout arg2 type2,………)
Language SQL contains SQL
Begin
  ……statement…..
End
Section of SP:

   Create procedure name:
     It   define name of store procedure.

     What    the name and data types of argument.

     In   – input variable.(Read only variable)

     Out    – output variable.(write only variable)

     inout   – both input and output.(read and write)
   Language SQL contains sql
     Option   can be
       Reads SQL   data
       Contains   SQL data
       Modifies SQL    data

   Begin ….End statement
     Logic   of store procedure
Example
   Code
create or replace procedure get_update(IN eno int, in sal int)
LANGUAGE SQL modifies sql data
begin
    update empPr set salary=sal where id=eno;
end;


Call get_update(3,20000);
Unit Question

   What is the use of in keyword?
   What is the difference between function and
    procedure?
   What is the use of contains, reads and modify data in
    function or procedure?
   What is function? Explain with example.
   What is procedure? Explain with example.
Practical example
   empBranch ( empno, designation, basic_sal, DOB,
    B_code)
   Branch( B_code, city)
   Write a procedure to give 10% bonus to all
    managers from ‘Ahemdabad’ branch.
ac_no      status   opndt   type
Example :                         101        S        10-3-11 Saving
                                  102        S        12-4-11 current
                                  103        S        10-2-12 saving
   Table :
       acct_mstr ( ac_no, status, opndt, type )
       Trans_mstr( trans_no, ac_no, dt,a_type,t_type,amt,balance)
       Inactive_acct (ac_no, opndt, type)

   Bank manager has decided to mark all those account as inactive(I)
    on which there are no transactions performed in last 365 days.

   Whenever any update takeplace,a record for same is maintained in
    inactive_acct table.
   Write plsql block using cursor to do same.

Contenu connexe

Tendances

Tendances (17)

Lecture 2. MS SQL. Stored procedures.
Lecture 2. MS SQL. Stored procedures.Lecture 2. MS SQL. Stored procedures.
Lecture 2. MS SQL. Stored procedures.
 
Procedures/functions of rdbms
Procedures/functions of rdbmsProcedures/functions of rdbms
Procedures/functions of rdbms
 
Stored procedure
Stored procedureStored procedure
Stored procedure
 
Introduction To Oracle Sql
Introduction To Oracle SqlIntroduction To Oracle Sql
Introduction To Oracle Sql
 
Sql Functions And Procedures
Sql Functions And ProceduresSql Functions And Procedures
Sql Functions And Procedures
 
4. plsql
4. plsql4. plsql
4. plsql
 
Packages - PL/SQL
Packages - PL/SQLPackages - PL/SQL
Packages - PL/SQL
 
Procedure n functions
Procedure n functionsProcedure n functions
Procedure n functions
 
SQL Server Stored procedures
SQL Server Stored proceduresSQL Server Stored procedures
SQL Server Stored procedures
 
SQL
SQLSQL
SQL
 
Oracle: PLSQL Introduction
Oracle: PLSQL IntroductionOracle: PLSQL Introduction
Oracle: PLSQL Introduction
 
Oracle: Procedures
Oracle: ProceduresOracle: Procedures
Oracle: Procedures
 
Function & procedure
Function & procedureFunction & procedure
Function & procedure
 
Programming in Oracle with PL/SQL
Programming in Oracle with PL/SQLProgramming in Oracle with PL/SQL
Programming in Oracle with PL/SQL
 
Query hierarchical data the easy way, with CTEs
Query hierarchical data the easy way, with CTEsQuery hierarchical data the easy way, with CTEs
Query hierarchical data the easy way, with CTEs
 
PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts
 
PL/SQL Part 1
PL/SQL Part 1PL/SQL Part 1
PL/SQL Part 1
 

Similaire à Unit 3

Unit 3(rdbms)
Unit 3(rdbms)Unit 3(rdbms)
Unit 3(rdbms)
Jay Patel
 
Tony Jambu (obscure) tools of the trade for tuning oracle sq ls
Tony Jambu   (obscure) tools of the trade for tuning oracle sq lsTony Jambu   (obscure) tools of the trade for tuning oracle sq ls
Tony Jambu (obscure) tools of the trade for tuning oracle sq ls
InSync Conference
 
SQL Server 2000 Research Series - Transact SQL
SQL Server 2000 Research Series - Transact SQLSQL Server 2000 Research Series - Transact SQL
SQL Server 2000 Research Series - Transact SQL
Jerry Yang
 
Database Foundation Training
Database Foundation TrainingDatabase Foundation Training
Database Foundation Training
Franky Lao
 
Sql tuning guideline
Sql tuning guidelineSql tuning guideline
Sql tuning guideline
Sidney Chen
 

Similaire à Unit 3 (20)

Unit 3(rdbms)
Unit 3(rdbms)Unit 3(rdbms)
Unit 3(rdbms)
 
Tony Jambu (obscure) tools of the trade for tuning oracle sq ls
Tony Jambu   (obscure) tools of the trade for tuning oracle sq lsTony Jambu   (obscure) tools of the trade for tuning oracle sq ls
Tony Jambu (obscure) tools of the trade for tuning oracle sq ls
 
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
 
SQL Server 2000 Research Series - Transact SQL
SQL Server 2000 Research Series - Transact SQLSQL Server 2000 Research Series - Transact SQL
SQL Server 2000 Research Series - Transact SQL
 
Sqlapi0.1
Sqlapi0.1Sqlapi0.1
Sqlapi0.1
 
IBM Informix dynamic server 11 10 Cheetah Sql Features
IBM Informix dynamic server 11 10 Cheetah Sql FeaturesIBM Informix dynamic server 11 10 Cheetah Sql Features
IBM Informix dynamic server 11 10 Cheetah Sql Features
 
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...
 
2° Ciclo Microsoft CRUI 3° Sessione: l'evoluzione delle piattaforme tecnologi...
2° Ciclo Microsoft CRUI 3° Sessione: l'evoluzione delle piattaforme tecnologi...2° Ciclo Microsoft CRUI 3° Sessione: l'evoluzione delle piattaforme tecnologi...
2° Ciclo Microsoft CRUI 3° Sessione: l'evoluzione delle piattaforme tecnologi...
 
DBA Commands and Concepts That Every Developer Should Know
DBA Commands and Concepts That Every Developer Should KnowDBA Commands and Concepts That Every Developer Should Know
DBA Commands and Concepts That Every Developer Should Know
 
Database Foundation Training
Database Foundation TrainingDatabase Foundation Training
Database Foundation Training
 
Procedures and triggers in SQL
Procedures and triggers in SQLProcedures and triggers in SQL
Procedures and triggers in SQL
 
Dynamic websites lec3
Dynamic websites lec3Dynamic websites lec3
Dynamic websites lec3
 
Tony jambu (obscure) tools of the trade for tuning oracle sq ls
Tony jambu   (obscure) tools of the trade for tuning oracle sq lsTony jambu   (obscure) tools of the trade for tuning oracle sq ls
Tony jambu (obscure) tools of the trade for tuning oracle sq ls
 
Assignment#08
Assignment#08Assignment#08
Assignment#08
 
Relational Database Management System
Relational Database Management SystemRelational Database Management System
Relational Database Management System
 
Sql tuning guideline
Sql tuning guidelineSql tuning guideline
Sql tuning guideline
 
SQL Tunning
SQL TunningSQL Tunning
SQL Tunning
 
Less09 Data
Less09 DataLess09 Data
Less09 Data
 

Plus de Abha Damani (20)

Unit2
Unit2Unit2
Unit2
 
Unit6
Unit6Unit6
Unit6
 
Unit5
Unit5Unit5
Unit5
 
Unit4
Unit4Unit4
Unit4
 
Unit3
Unit3Unit3
Unit3
 
Unit 1 introduction to visual basic programming
Unit 1 introduction to visual basic programmingUnit 1 introduction to visual basic programming
Unit 1 introduction to visual basic programming
 
Ch14
Ch14Ch14
Ch14
 
Ch12
Ch12Ch12
Ch12
 
Ch11
Ch11Ch11
Ch11
 
Ch10
Ch10Ch10
Ch10
 
Ch08
Ch08Ch08
Ch08
 
Ch01 enterprise
Ch01 enterpriseCh01 enterprise
Ch01 enterprise
 
3 data mgmt
3 data mgmt3 data mgmt
3 data mgmt
 
2 it supp_sys
2 it supp_sys2 it supp_sys
2 it supp_sys
 
1 org.perf it supp_appl
1 org.perf it supp_appl1 org.perf it supp_appl
1 org.perf it supp_appl
 
Managing and securing the enterprise
Managing and securing the enterpriseManaging and securing the enterprise
Managing and securing the enterprise
 
Ch6
Ch6Ch6
Ch6
 
Unit2
Unit2Unit2
Unit2
 
Unit 4
Unit 4Unit 4
Unit 4
 
Unit 5
Unit 5Unit 5
Unit 5
 

Dernier

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Dernier (20)

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
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
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 

Unit 3

  • 1. UNIT : 3 APPLICATION DEVELOPMENT USING PROCEDURAL SQL Prepared By : Preeti Bhatt
  • 2. Content :  Cursors : OPEN CLOSE and FETCH  Creation of User Defined Function  Creation of Stored Procedure
  • 3. Cursor  code
  • 4. Creating User Defined Function  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. Syntax 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. Example(simple) create or replace function simple_function() returns varchar(10) begin return 'hello'; end; ;
  • 7. Example  Create or replace function bonus(salary int, bonus int) returns int return salary*bonus/100 Example
  • 8. Example ( modifies data) 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. Return Table  Function also used to return table.  code
  • 10. Stored Procedure  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.  Procedure does not return any value.
  • 11. Characteristics :  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. Benefits of SP  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 direct access to the content of the database .  Reduced development cost.  Centralized security and maintenance.
  • 13. Structure of SP Create or replace procedure procedure_name (in | out | inout arg1 type1, in | out | inout arg2 type2,………) Language SQL contains SQL Begin ……statement….. End
  • 14. Section of SP:  Create procedure name:  It define name of store procedure.  What the name and data types of argument.  In – input variable.(Read only variable)  Out – output variable.(write only variable)  inout – both input and output.(read and write)
  • 15. Language SQL contains sql  Option can be  Reads SQL data  Contains SQL data  Modifies SQL data  Begin ….End statement  Logic of store procedure
  • 16. Example  Code create or replace procedure get_update(IN eno int, in sal int) LANGUAGE SQL modifies sql data begin update empPr set salary=sal where id=eno; end; Call get_update(3,20000);
  • 17. Unit Question  What is the use of in keyword?  What is the difference between function and procedure?  What is the use of contains, reads and modify data in function or procedure?  What is function? Explain with example.  What is procedure? Explain with example.
  • 18. Practical example  empBranch ( empno, designation, basic_sal, DOB, B_code)  Branch( B_code, city)  Write a procedure to give 10% bonus to all managers from ‘Ahemdabad’ branch.
  • 19. ac_no status opndt type Example : 101 S 10-3-11 Saving 102 S 12-4-11 current 103 S 10-2-12 saving  Table :  acct_mstr ( ac_no, status, opndt, type )  Trans_mstr( trans_no, ac_no, dt,a_type,t_type,amt,balance)  Inactive_acct (ac_no, opndt, type)  Bank manager has decided to mark all those account as inactive(I) on which there are no transactions performed in last 365 days.  Whenever any update takeplace,a record for same is maintained in inactive_acct table.  Write plsql block using cursor to do same.