Oracle Stored Procedure

Source: Internet
Author: User

The Oracle stored procedure consists of three parts: Process Declaration, execution process, and stored procedure exception.

  1. Oracle stored procedures can contain parameter stored procedures and parameter stored procedures.
  2. I. No parameter program process syntax
  3. 1Create Or Replace ProcedureNoParPro
  4. 2As;
  5. 3Begin
  6. 4;
  7. 5 exception // The stored procedure is abnormal.
  8. 6;
  9. 7End;
  10. 8
  11. Ii. Example of stored procedure with Parameters
  12. 1Create Or Replace ProcedureQueryempname (sfindno emp. empno % type)As
  13. 2 sName emp. ename % type;
  14. 3 sjob emp. job % type;
  15. 4Begin
  16. 5 ....
  17. 7 exception
  18. ....
  19. 14End;
  20. 15
  21. Iii. Parameter stored procedures and value assignment methods
  22. 1Create Or Replace ProcedureRunbyparmeters (isalInEmp. sal % type,
  23. SnameOut Varchar, SjobIn Out Varchar)
  24. 2AsIcount number;
  25. 3Begin
  26. 4Select Count(*)IntoIcountFromEmpWhereSal> isalAndJob = sjob;
  27. 5 if icount = 1Then
  28. 6 ....
  29. 9Else
  30. 10 ....
  31. 12EndIf;
  32. 13 exception
  33. 14WhenToo_many_rowsThen
  34. 15 DBMS_OUTPUT.PUT_LINE ('Return value more than 1 Line');
  35. 16WhenOthersThen
  36. 17 DBMS_OUTPUT.PUT_LINE ('An error occurred during the RUNBYPARMETERS process! ');
  37. 18End;
  38. 19
  39. 4. Calling stored procedures in Oracle
  40. Method 1
  41. 1Declare
  42. 2 realsal emp. sal % type;
  43. 3 realnameVarchar(40 );
  44. 4 realjobVarchar(40 );
  45. 5Begin// The Stored Procedure Call starts.
  46. 6. realsal: = 1100;
  47. 7 realname: ='';
  48. 8 realjob: ='Cler';
  49. 9 runbyparmeters (realsal, realname, realjob); -- must be in order
  50. 10 DBMS_OUTPUT.PUT_LINE (REALNAME |''| REALJOB );
  51. 11END; // Process call ends
  52. 12
  53. Method 2
  54. 1Declare
  55. 2 realsal emp. sal % type;
  56. 3 realnameVarchar(40 );
  57. 4 realjobVarchar(40 );
  58. 5Begin// Process call starts
  59. 6. realsal: = 1100;
  60. 7 realname: ='';
  61. 8 realjob: ='Cler';
  62. 9 runbyparmeters (sname => realname, isal => realsal, sjob => realjob); -- the variable sequence of the specified value is variable.
  63. 10 DBMS_OUTPUT.PUT_LINE (REALNAME |''| REALJOB );
  64. 11END; // Process call ends
  65. 12

Related Article

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.