龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 数据库类 > Oracle 技术 >

Oracle存储过程的实际用法解剖

时间:2011-04-12 23:18来源:未知 作者:admin 点击:
分享到:
以下的文章主要讲述的是 Oracle 存储过程的实际的用法,本文是以想关的实际应用代码的方式来引出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;  

根据编号返回记录

  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存储过程的用法的描述,希望会给你带来一些帮助在此方面。

精彩图集

赞助商链接