Oracle存储过程实际应用代码详细描述

以下的文章主要介绍的是Oracle存储过程的实际操作用法,本文主要是以相关实际应用代码的方式来引出Oracle存储过程的实际操作,下面就是文章的具体内容介绍,望你浏览之后会对其有更深的了解。

 
 
 
  1. create table stuInfo  
  2. (  
  3. stuID int primary key,  
  4. stuName varchar2(20)  
  5. )  
  6. create or replace procedure proc1  
  7. is  
  8. begin  
  9. insert into stuInfo values(1,'liheng');  
  10. end;  
  11. create or replace procedure proc2  
  12. (  
  13. v_ID int,  
  14. v_Name varchar2  
  15. )  
  16. is  
  17. begin  
  18. insert into stuInfo values(v_ID,v_Name);  
  19. commit;  

记得要提交

 

 
 
 
  1. end;  
  2. create or replace procedure proc3  
  3. (  
  4. v_ID int,  
  5. v_Name out varchar2  
  6. )  
  7. is  
  8. varName stuInfo.Stuname%type;  
  9. begin  
  10. select stuName into varName from stuInfo where stuID=v_ID;  
  11. v_Name:=varName;  
  12. end;  

 

返回全部记录

 
 
 
  1. create or replace package PKG_STUINFO is  
  2. type stuInfoCursorType is ref cursor;  
  3. procedure getStuInfo (stuInfoCursor out stuInfoCursorType);  
  4. end;  
  5. create or replace package body PKG_STUINFO is  
  6. procedure getStuInfo (stuInfoCursor out stuInfoCursorType)  
  7. is  
  8. var_cursor stuInfoCursorType;  
  9. begin  
  10. open var_cursor for select * from stuInfo;  
  11. stuInfoCursor:=var_cursor;  
  12. end;  
  13. end;  

 

Oracle存储过程的中我们要根据编号返回记录

 
 
 
  1. create or replace package PKG_STUINFO is  
  2. type stuInfoCursorType is ref cursor;  
  3. procedure getStuInfo (v_ID int,stuInfoCursor out stuInfoCursorType);  
  4. end;  
  5. create or replace package body PKG_STUINFO is  
  6. procedure getStuInfo (v_ID int,stuInfoCursor out stuInfoCursorType)  
  7. is  
  8. var_cursor stuInfoCursorType;  
  9. begin  
  10. if v_ID=0 then  
  11. open var_cursor for select * from stuInfo;  
  12. else  
  13. open var_cursor for select * from stuInfo where stuID=v_ID;  
  14. end if;  
  15. stuInfoCursor:=var_cursor;  
  16. end;  
  17. end;  

 

根据姓名返回记录

 
 
 
  1. create or replace package PKG_STUINFO is  
  2. type stuInfoCursorType is ref cursor;  
  3. procedure getStuInfo (v_Name varchar2,stuInfoCursor out stuInfoCursorType);  
  4. end;  
  5. create or replace package body PKG_STUINFO is  
  6. procedure getStuInfo (v_Name varchar2,stuInfoCursor out stuInfoCursorType)  
  7. is  
  8. var_cursor stuInfoCursorType;  
  9. begin  
  10. if v_Name =' ' then  
  11. open var_cursor for select * from stuInfo;  
  12. else  
  13. open var_cursor for select * from stuInfo where stuName like '%'||v_Name||'%';  
  14. end if;  
  15. stuInfoCursor:=var_cursor;  
  16. end;  
  17. end;   

上述的相关内容就是对Oracle存储过程的用法的描述,希望会给你带来一些帮助在此方面。

【编辑推荐】

  1. Oracle存储过程中的定时执行方法有哪些?
  2. 对Oracle 10g中hints调整机制解析
  3. Oracle提高SQL在数据库中执行效率,不得不看
  4. Oracle性能调整的方案的描述
  5. Oracle数据库性能的几大优点介绍
THE END