Oracle存储过程的详细分析


  本文标签:Oracle存储过程

  以下的文章主要是Oracle存储过程(增、删、改)写法的介绍,以目前的相关形式分析,发现自己所要在对其方面的学习的东西简直是太多了,甚至找不到头绪,例如:数据库、开发技术、管理……这些技术东西  。

  一天一天都在更新,要想跟得上脚步,估计要把自己累趴下,还是要把自己善于的方面做好,做精也就差不多了  。

  好久都没有写过Oracle存储过程了,一般写查询语句比较多,自己就试着写了一下插入、删除、修改记录的存储过程  。

  插入:

  代码

  

  1. CREATE OR REPLACE Procedure p_insert_t_stu --存储过程名称  
  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;  

  

  删除:

  代码

  

  1. CREATE OR REPLACE Procedure p_delete_t_stu --存储过程名称  
  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:=删除成功;  
  18. End;  
  19. End If;  
  20. Exception  
  21. When Others Then  
  22. p_msg:=Sqlerrm || , || 删除失败;  
  23. END;  

  

  修改:

  代码

  

  1. CREATE OR REPLACE Procedure p_update_t_stu --存储过程名称  
  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;   

  以上的相关内容就是对Oracle存储过程的介绍,望你能有所收获  。