Detailed analysis of Oracle stored procedures

Source: Internet
Author: User

The following articles mainly describe the writing of Oracle stored procedures (add, delete, and modify), which are analyzed in the current form, I find that I have too many things to learn from, or even cannot find a clue, such as databases, development technologies, management ...... These technologies.

Update every day. If you want to keep up with your step, you may need to get tired of yourself, or do your best in terms of expertise.

I haven't written any Oracle stored procedures for a long time. Generally, I write a lot of query statements and try to write the stored procedures of inserting, deleting, and modifying records.

Insert:

Code

 
 
  1. Create or replace Procedure p_insert_t_stu -- stored Procedure name
  2. (
  3. P_stuid in Number,
  4. P_stuname in Nvarchar2,
  5. P_stusex in Nvarchar2,
  6. P_stuadd in Nvarchar2
  7. )
  8. As
  9. BEGIN
  10. Insert into t_stu
  11. Values
  12. (P_stuid, p_stuname, p_stusex, p_stuadd );
  13. Commit;
  14. End;

Delete:

Code

 
 
  1. Create or replace Procedure p_delete_t_stu -- stored Procedure name
  2. (
  3. P_stuid in Number,
  4. P_msg Out Nvarchar2
  5. )
  6. Is
  7. Flag Integer: = 1;
  8. V_stuid Number;
  9. Begin
  10. Select flag Into v_stuid From t_stu Where stuid = p_stuid;
  11. Delete t_stu
  12. Where
  13. Stuid = p_stuid;
  14. Commit;
  15. If flag = 1 Then
  16. Begin
  17. P_msg: = 'deleted successfully ';
  18. End;
  19. End If;
  20. Exception
  21. When Others Then
  22. P_msg: = Sqlerrm | ',' | 'deletion failed ';
  23. END;

Modify:

Code

 
 
  1. Create or replace Procedure p_update_t_stu -- stored Procedure name
  2. (
  3. P_stuid in Number,
  4. P_stuname in Nvarchar2,
  5. P_stusex in Nvarchar2,
  6. P_stuadd in Nvarchar2
  7. )
  8. As
  9. BEGIN
  10. Update t_stu Set stuname = p_stuname, stusex = p_stusex, stuadd = p_stuadd
  11. Where
  12. Stuid = p_stuid;
  13. Commit;
  14. End;

The above content is an introduction to the Oracle stored procedure. I hope you will find some gains.

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.