Oracle Stored Procedure syntax

Source: Internet
Author: User

 

  1. The Stored Procedure contains three parts: Declaration, execution, and exception.
  2. There are no parameter programs or stored procedures with parameters.
  3. No parameter program syntax
  4. 1 create or replace procedure noparpro
  5. 2;
  6. 3 begin
  7. 4;
  8. 5 exception
  9. 6;
  10. 7 end;
  11. 8
  12. Example of a stored procedure with Parameters
  13. 1 create or replace procedure queryempname (sfindno EMP. empno % Type)
  14. 2 sname EMP. ename % type;
  15. 3 sjob EMP. Job % type;
  16. 4 begin
  17. 5 ....
  18. 7 exception
  19. ....
  20. 14 end;
  21. 15
  22. Stored Procedures with parameters include the Assignment Method
  23. 1 create or replace procedure runbyparmeters (isal in EMP. Sal % type,
  24. Sname out varchar, sjob in out varchar)
  25. 2 As icount number;
  26. 3 begin
  27. 4 select count (*) into icount from EMP where SAL> isal and job = sjob;
  28. 5IfIcount = 1 then
  29. 6 ....
  30. 9Else
  31. 10 ....
  32. 12 EndIf;
  33. 13 exception
  34. 14 when too_many_rows then
  35. 15 dbms_output.put_line ('Return value more than 1 line ');
  36. 16 when others then
  37. 17 dbms_output.put_line ('An error occurred during runbyparmeters! ');
  38. 18 end;
  39. 19
  40. Process call
  41. Method 1
  42. 1 declare
  43. 2 realsal EMP. Sal % type;
  44. 3 realname varchar (40 );
  45. 4 realjob varchar (40 );
  46. 5 begin
  47. 6. realsal: = 1100;
  48. 7 realname: = '';
  49. 8 realjob: = 'cler ';
  50. 9 runbyparmeters (realsal, realname, realjob); -- must be in order
  51. 10 dbms_output.put_line (realname | ''| realjob );
  52. 11 end;
  53. 12
  54. Method 2
  55. 1 declare
  56. 2 realsal EMP. Sal % type;
  57. 3 realname varchar (40 );
  58. 4 realjob varchar (40 );
  59. 5 begin
  60. 6. realsal: = 1100;
  61. 7 realname: = '';
  62. 8 realjob: = 'cler ';
  63. 9 runbyparmeters (sname => realname, isal => realsal, sjob => realjob); -- the variable sequence of the specified value is variable.
  64. 10 dbms_output.put_line (realname | ''| realjob );
  65. 11 end;
  66. 12
The Stored Procedure contains three parts: Declaration, execution, and exception. There are no parameter programs or stored procedures with parameters. No parameter program Syntax 1 create or replace procedure noparpro2 as; 3 begin4; 5 exception6; 7 end; 8 with parameter Stored Procedure instance 1 create or replace procedure queryempname (sfindno EMP. empno % Type) as 2 sname EMP. ename % type; 3 sjob EMP. job % type; 4 Begin 5 .... 7 exception .... 14 end; 15 with parameter stored procedures include assignment method 1 create or replace procedure runbyparmeters (isal in EMP. sal % type, sname out varchar, sjob in out varchar) 2 as icount number; 3 begin 4 Se Lect count (*) into icount from EMP where SAL> isal and job = sjob; 5 If icount = 1 then 6 .... 9 else10 .... 12 end if; 13 exception14 when too_many_rows then15 dbms_output.put_line ('Return value more than 1 row'); 16 when others then17 dbms_output.put_line ('error in runbyparmeters process! '); 18 end; 19 process call method 1 declare 2 realsal EMP. sal % type; 3 realname varchar (40); 4 realjob varchar (40); 5 begin 6 realsal: = 1100; 7 realname: = ''; 8 realjob: = 'cler'; 9 runbyparmeters (realsal, realname, realjob); -- the order must be 10 dbms_output.put_line (realname | ''| realjob); 11 end; 12 method 2 1 declare 2 realsal EMP. sal % type; 3 realname varchar (40); 4 realjob varchar (40); 5 begin 6 realsal: = 1100; 7 realname: = ''; 8 realjob: = 'cler'; 9 runbyparmeters (sname => realname, isal => realsal, sjob => realjob ); -- The variable sequence corresponding to the specified value can be 10 dbms_output.put_line (realname | ''| realjob); 11 end; 12

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.