Oracle Database package construction process instance

Source: Internet
Author: User

Oracle DatabasePackageConstruction ProcessThere is no name. It is the part that begins with begin and ends with end after other processes of the package are implemented. This article introduces an example of the construction process. Let's take a look at this part.

1. Baotou

 
 
  1. create or replace package pkg_emp is  
  2.   minsal number(6, 2);  
  3.   maxsal number(6, 2);  
  4.   procedure add_employee(eno    number,  
  5.                          name   varchar2,  
  6.                          salary number,  
  7.                          dno    number);  
  8.   procedure upd_sal(eno number, salary number);  
  9.   procedure upd_sal(name varchar2, salary number);  
  10. end pkg_emp; 

2. Package body

 
 
  1. Create or replace package body pkg_emp is
  2.  
  3. Procedure add_employee (eno number,
  4. Name varchar2,
  5. Salary number,
  6. Dno number) is
  7. Begin
  8. If salary between minsal and maxsal then
  9. Insert into emp
  10. (Empno, ename, sal, deptno)
  11. Values
  12. (Eno, name, salary, dno );
  13. Else
  14. Raise_application_error (-20001, 'salary out of range ');
  15. End if;
  16. Exception
  17. When dup_val_on_index then
  18. Raise_application_error (-20002, 'this employee already exists ');
  19. End;
  20.  
  21. Procedure upd_sal (eno number, salary number) is
  22. Begin
  23. If salary between minsal and maxsal then
  24. Update emp set sal = salary where empno = eno;
  25. If SQL % notfound then
  26. Raise_application_error (-20003, 'employee No. Does not exist ');
  27. End if;
  28. Else
  29. Raise_application_error (-20001, 'salary out of range ');
  30. End if;
  31. End;
  32.  
  33. Procedure upd_sal (name varchar2, salary number) is
  34. Begin
  35. If salary between minsal and maxsal then
  36. Update emp set sal = salary where upper (ename) = upper (name );
  37. If SQL % notfound then
  38. Raise_application_error (-20004, 'employee No. Does not exist ');
  39. End if;
  40. Else
  41. Raise_application_error (-20001, 'salary out of range ');
  42. End if;
  43. End;

3. Construction Process

 
 
  1. begin    
  2. select min(sal), max(sal) into minsal, maxsal from emp;    
  3. end;  

Here is an introduction to the Oracle database package construction process instance. I hope this introduction will be helpful to you!

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.