oracle中 包,Oracle 中包的应用

这个博客介绍了如何在Oracle数据库中创建和使用包。包`pck_infos`包含了用于管理学生信息的一系列过程,包括初始化、显示学生列表、添加、删除和修改学生记录。此外,还定义了用于判断学生信息是否存在和显示消息的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

(

1

)创建包头

create

or

replace

package pck_infos

as

--

总数量

v_infos_count

number

;

--

初始化操作

procedure

p_init(p_max

number

, p_min

number

);

--

显示学生列表数据

procedure

p_list_infos;

--

增加一条学生记录

procedure

p_add_infos(

p_stuid infos.stuid

%

type,

p_stuname infos.stuname

%

type,

p_gender infos.gender

%

type,

p_age infos.age

%

type,

p_seat infos.seat

%

type,

p_enrolldate infos.enrolldate

%

type,

p_stuaddress infos.stuaddress

%

type,

p_classno infos.classno

%

type);

--

删除一条学生记录

procedure

p_delete_infos(p_stuid infos.stuid

%

type);

--

根据stuid修改学生的姓名

procedure

p_edit_infos_name(

p_stuid infos.stuid

%

type,

p_stuname infos.stuname

%

type);

end

;

(

2

)创建包体

create

or

replace

package body pck_infos

as

v_msg

varchar2

(

100

);

--

show message

v_max_age

number

;

--

max age

v_min_age

number

;

--

min age

--

判断学生是否存在

function

f_exist_infos(p_stuid infos.stuid

%

type)

return

boolean;

--

show msg

procedure

p_show_msg;

--

初始化操作

procedure

p_init(p_max

number

, p_min

number

)

as

begin

select

count

(stuid)

into

v_infos_count

from

infos;

v_max_age:

=

p_max;

v_min_age:

=

p_min;

v_msg:

=

'

init finished!

'

;

p_show_msg;

end

p_init;

--

显示信息

procedure

p_show_msg

as

begin

dbms_output.put_line(v_msg);

end

p_show_msg;

--

判断学生是否存在

function

f_exist_infos(p_stuid infos.stuid

%

type)

return

boolean

as

v_num

number

;

begin

select

count

(stuid)

into

v_num

from

infos

where

stuid

=

p_stuid;

if

v_num

=

1

then

return

true;

else

return

false;

end

if

;

end

f_exist_infos;

--

显示学生列表数据

procedure

p_list_infos

as

v_infos_record infos

%

rowtype;

cursor

cur_infos

is

select

*

from

infos;

begin

open

cur_infos;

loop

fetch

cur_infos

into

v_infos_record;

exit

when

cur_infos

%

notfound;

dbms_output.put_line(

'

stuid:

'

||

v_infos_record.stuid);

end

loop;

close

cur_infos;

end

p_list_infos;

--

增加一条学生记录

procedure

p_add_infos(

p_stuid infos.stuid

%

type,

p_stuname infos.stuname

%

type,

p_gender infos.gender

%

type,

p_age infos.age

%

type,

p_seat infos.seat

%

type,

p_enrolldate infos.enrolldate

%

type,

p_stuaddress infos.stuaddress

%

type,

p_classno infos.classno

%

type)

as

begin

if

not

f_exist_infos(p_stuid)

then

insert

into

infos(stuid,stuname,gender,age,seat,enrolldate,stuaddress,classno)

values

(p_stuid,p_stuname,p_gender,p_age,p_seat,p_enrolldate,p_stuaddress,p_classno);

commit

;

v_infos_count:

=

v_infos_count

+

1

;

else

v_msg:

=

'

already exist!

'

;

end

if

;

end

p_add_infos;

--

删除一条学生记录

procedure

p_delete_infos(p_stuid infos.stuid

%

type)

as

begin

if

f_exist_infos(p_stuid)

then

delete

from

infos

where

stuid

=

p_stuid;

commit

;

v_infos_count:

=

v_infos_count

-

1

;

else

v_msg:

=

'

not exist infos!

'

;

end

if

;

end

p_delete_infos;

--

根据stuid修改学生的姓名

procedure

p_edit_infos_name(

p_stuid infos.stuid

%

type,

p_stuname infos.stuname

%

type)

as

begin

if

f_exist_infos(p_stuid)

then

update

infos

set

stuname

=

p_stuname

where

stuid

=

p_stuid;

commit

;

else

v_msg:

=

'

not exists infos

'

;

end

if

;

end

p_edit_infos_name;

end

;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值