- 1、本文档共5页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 5、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 6、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 7、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 8、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
实验和
1、游标的应用
单个标的游标
declare yx cursor for
select * from 院系
open yx
FETCH yx
close yx
deallocate yx
嵌套游标
declare @xuehao char(10),@name char(10),@yuanxi char(10)
declare @kcbh char(8),@chengji char(10)
declare xs cursor for
select 学号,姓名,院系from 学生
open xs
fetch from xs into @xuehao,@name,@yuanxi
while @@fetch_status=0
begin
print 学号:+@xuehao+姓名:+@name+所在院系为:+@yuanxi+所修课程
declare xk cursor for
select 课程编号,成绩from 选课where 学号=@xuehao
open xk
fetch from xk into @kcbh,@chengji
while @@fetch_status=0
begin
print @kcbh+的成绩是:+@chengji
fetch from xk into @kcbh,@chengji
end
close xk
deallocate xk
fetch from xs into @xuehao,@name,@yuanxi
end
close xs
deallocate xs
存储过程
(1)
1、查询平均分数在x到y范围内的学生信息。
create procedure stu
@x int,@y int
as
select 学号,姓名,名称,平均成绩 from 学生join 院系 on 院系.编号=学生.院系
where 平均成绩between @x and @y
execute stu 60,70
2、更新操作,以学号、课程编号和考试成绩作参数更新指定学生和课程的考试成绩,并返回该学生的平均成绩。
create procedure stu1
@xh char(8),
@kcbh char(8),
@cj int,
@currencycursor1 cursor varying output
as
declare @avg smallint
set @currencycursor1 =CURSOR for
select * from 选课
open @currencycursor1;
declare @xhh char(8),@kcbhh char(8),@cjj int
fetch from @currencycursor1 into @xhh, @kcbhh,@cjj
while @@FETCH_STATUS=0
begin
if @xhh=@xh and @kcbhh=@kcbh
begin
update 选课 set 成绩=@cj where current of @currencycursor1
end
fetch from @currencycursor1 into @xhh,@kcbhh,@cjj
end
close @currencycursor1
deallocate @currencycursor1
select @avg=AVG(成绩) from 选课
where 学号=@xh
return @avg
declare @avg smallint,@currencycursor cursor
execute @avg=stu1 002,05,82,@currencycursor
print 学号002的平均成绩为+str(@avg)
(2)
自行再分别设计一个完成查询和完成操作功能的存储过程(在实验报告中要准确描述功能需求)
1、查询功能为:找出学时在一定范围内的课程的信息
create procedure stu2
@a int,@b int
as
select * from 课程
where 学时between @a and @b
execute stu1 24,40
2、功能为:删除指定教师编号的教师的编号,并返回工资
create procedure stu3
@jsbh char(8),
@currencycursor cursor varying output
as
declare @salary char(10)
set @currencycursor =CURSOR for
select 教师编号
from 教师
open @currencycursor;
declare @js
您可能关注的文档
最近下载
- 2025年浙江安防职业技术学院单招职业技能测试题库(名校卷).docx
- 2024年广州中考英语听说考试——“信息询问” 情景训练课件.pptx
- 四年级下册单元作文《热爱生命》.ppt
- 骆驼奶营养价值课件.pptx
- 统编版高中语文教材中杜甫四首诗《登高》《登岳阳楼》《蜀相》《客至》联读.docx
- 附件3-2:12千伏一二次融合环网柜(箱)及配电自动化终端(DTU)标准化设计方案(2021版).pdf VIP
- 第6课 戊戌变法 课件(共34张PPT).pptx
- 2023年上海杉达学院工程管理专业《管理学》科目期末试卷A(有答案).docx VIP
- 分包考核管理办法和考核表.pdf VIP
- 送教上门康复教案.docx
文档评论(0)