1 / 131

PL/SQL

PL/SQL. PL/SQL. What is it ?. PL/SQL. What is it ? PL/SQL = procedural Programming Language + SQL. PL/SQL. What is it ? PL/SQL = procedural P rogramming L anguage + SQL. PL/SQL. Why do we need it ?. PL/SQL. Why do we need it ? To bridge a gap between high level

sven
Télécharger la présentation

PL/SQL

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PL/SQL

  2. PL/SQL • What is it ?

  3. PL/SQL • What is it ? PL/SQL = procedural Programming Language + SQL

  4. PL/SQL • What is it ? PL/SQL = procedural Programming Language + SQL

  5. PL/SQL • Why do we need it ?

  6. PL/SQL • Why do we need it ? To bridge a gap between high level declarative query language and procedural programming language

  7. PL/SQL • Advantages

  8. PL/SQL • Advantages • PL/SQL provides procedural capabilities

  9. PL/SQL • Advantages • PL/SQL provides procedural capabilities • PL/SQL improves performance

  10. PL/SQL • Advantages • PL/SQL provides procedural capabilities • PL/SQL improves performance • PL/SQL enhances productivity

  11. PL/SQL • Advantages • PL/SQL provides procedural capabilities • PL/SQL improves performance • PL/SQL enhances productivity • PL/SQL enables portability

  12. PL/SQL • Advantages • PL/SQL provides procedural capabilities • PL/SQL improves performance • PL/SQL enhances productivity • PL/SQL enables portability • PL/SQL integrates RDBMSs

  13. PL/SQL • Overview

  14. PL/SQL • Overview PL/SQL = INSERT + UPDATE + DELETE + SELECT +

  15. PL/SQL • Overview PL/SQL = INSERT + UPDATE + DELETE + SELECT + variables +

  16. PL/SQL • Overview PL/SQL = INSERT + UPDATE + DELETE + SELECT + variables + assignment statements +

  17. PL/SQL • Overview PL/SQL = INSERT + UPDATE + DELETE + SELECT + variables + assignment statements + conditional control statement +

  18. PL/SQL • Overview PL/SQL = INSERT + UPDATE + DELETE + SELECT + variables + assignment statements + conditional control statement + repetition statement +

  19. PL/SQL • Overview PL/SQL = INSERT + UPDATE + DELETE + SELECT + variables + assignment statements + conditional control statement + repetition statement + exception handling +

  20. PL/SQL • Overview PL/SQL = INSERT + UPDATE + DELETE + SELECT + variables + assignment statements + conditional control statement + repetition statement + exception handling + procedures and functions +

  21. PL/SQL • Overview PL/SQL = INSERT + UPDATE + DELETE + SELECT + variables + assignment statements + conditional control statement + repetition statement + exception handling + procedures and functions + packages

  22. PL/SQL • Program structure

  23. PL/SQL • Program structure • PL/SQL is a block-structured language

  24. PL/SQL • Program structure • PL/SQL is a block-structured language It means that its basic units like procedures, functions and anonymous blocks that make up PL/SQL program are logical blocks, which can contain a number of nested sub-blocks

  25. PL/SQL • Block structure

  26. PL/SQL • Block structure • PL/SQL block, procedure, function consist of the following components:

  27. PL/SQL • Block structure • PL/SQL block, procedure, function consist of the following components: • declarative component,

  28. PL/SQL • Block structure • PL/SQL block, procedure, function consist of the following components: • declarative component, • executable component,

  29. PL/SQL • Block structure • PL/SQL block, procedure, function consist of the following components: • declarative component, • executable component, • exception component

  30. PL/SQL • Declarative component

  31. PL/SQL • Declarative component DECLARE -- declarations

  32. PL/SQL • Declarative component DECLARE stock_num NUMBER(5); stock_name VARCHAR(5); dob DATE;

  33. PL/SQL • Executable component BEGIN -- PL/SQL statements

  34. PL/SQL • Executable component BEGIN stock_num := 23098;

  35. PL/SQL • Executable component BEGIN stock_num := 23098; SELECT sname INTO stock_name FROM Inventory WHERE snum = stock_num;

  36. PL/SQL • Executable component BEGIN stock_num := 23098; SELECT sname INTO stock_name FROM Inventory WHERE snum = stock_num; IF stock_name = ‘bolt’ THEN

  37. PL/SQL • Executable component BEGIN stock_num := 23098; SELECT sname INTO stock_name FROM Inventory WHERE snum = stock_num; IF stock_name = ‘bolt’ THEN UPDATE Inventory SET quantity = quantity -1; WHERE snum = stock_num; ELSE IF;

  38. PL/SQL • Exception component

  39. PL/SQL • Exception component EXCEPTION -- exception handlers

  40. PL/SQL • Exception component EXCEPTION WHEN NO_DATA_FOUND THEN INSERT INTO emp_audit VALUES( emp_id, 'No such number' );

  41. PL/SQL • Exception component EXCEPTION WHEN NO_DATA_FOUND THEN INSERT INTO emp_audit VALUES( emp_id, 'No such number' ); WHEN OTHERS THEN INSERT INTO emp_error VALUES( sysdate, sqlerrm);

  42. PL/SQL • Block structure DECLARE -- declarations BEGIN -- statements EXCEPTION -- handlers END;

  43. PL/SQL • Procedure structure PROCEDURE name ... -- declarations BEGIN -- statements EXCEPTION -- handlers END name;

  44. PL/SQL • Function structure FUNCTION name ... -- declarations BEGIN -- statements EXCEPTION -- handlers END name;

  45. PL/SQL Example -- This is a comment

  46. PL/SQL Example -- This is a comment DECLARE average NUMBER(5,2);

  47. PL/SQL Example -- This is a comment DECLARE average NUMBER(5,2); BEGIN SELECT avg(salary) INTO average FROM Supplier;

  48. PL/SQL Example -- This is a comment DECLARE average NUMBER(5,2); BEGIN SELECT avg(salary) INTO average FROM Supplier; IF average > 3000 THEN UPDATE Supplier SET salary = salary + 100;

  49. PL/SQL Example -- This is a comment DECLARE average NUMBER(5,2); BEGIN SELECT avg(salary) INTO average FROM Supplier; IF average > 3000 THEN UPDATE Supplier SET salary = salary + 100; ELSE UPDATE Supplier SET salary = salary + 200; END IF; END;

  50. PL/SQL • Declarations

More Related