Diese Präsentation wurde erfolgreich gemeldet.
Die SlideShare-Präsentation wird heruntergeladen. ×
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Nächste SlideShare
Unit 3(rdbms)
Unit 3(rdbms)
Wird geladen in …3
×

Hier ansehen

1 von 19 Anzeige

Weitere Verwandte Inhalte

Diashows für Sie (18)

Ähnlich wie Unit 3 (20)

Anzeige

Aktuellste (20)

Anzeige

Unit 3

  1. 1. UNIT : 3 APPLICATION DEVELOPMENT USING PROCEDURAL SQL Prepared By : Preeti Bhatt
  2. 2. Content :  Cursors : OPEN CLOSE and FETCH  Creation of User Defined Function  Creation of Stored Procedure
  3. 3. Cursor  code
  4. 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. 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. 6. Example(simple) create or replace function simple_function() returns varchar(10) begin return 'hello'; end; ;
  7. 7. Example  Create or replace function bonus(salary int, bonus int) returns int return salary*bonus/100 Example
  8. 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. 9. Return Table  Function also used to return table.  code
  10. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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.

×