Topic: Oracle认证:Oracle存储过程的实际用法解剖

ERP俱乐部

第 1 页 总共 1 页 [共有 1 条记录]


Posted by 半神 on 2011-09-28 10:53 上午

本文是以想关的实际应用代码的方式来引出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存储过程的用法的描述,希望会给你带来一些帮助在此方面。