欢迎来到天天文库
浏览记录
ID:28042171
大小:47.50 KB
页数:4页
时间:2018-12-07
《存储过程的应用》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、存储过程练习题版本1.01.现有以下2张表,存取款是在银行里的交易情况,储户动态信息表是储户在银行的存款金额,现在创建一个触发器,实现当我们在存取款中取钱或存钱时,储户动态信息表中存款金额也要发生相应的改变,当存钱时就加,取钱时就减。当cke<0时透支时,就不给取款a.createtable存取款表(金额money,--存取金额标志int,--存取标志1为存,0为取账号char(15),-账号)createtableaccount_asscess(accountnochar(15)notnull,flagint,moneynumber(10,
2、2))b.createtable储户动态信息表(账号char(15)primarykey存款额money)createtabledepositor(accountnochar(15)primarykey,moneynumber(10,2)notnull)createorreplacetriggeraccount_triggerafterupdateondepositorforeachrowdeclare一一localvariableshereflagint;beginif:new.money〉:old.moneythenflag:=l;els
3、if:new.money<:old.moneythenflag:=0;if:new.money<0thengotoover;endif;endif;insertintoaccount_asscessvalues(:new.accountno,flag,(:new.money-:old.money));<>null;endaccount_trigger;insertintodepositorvalues(r1234567890123451000)可以透支的:createorreplaceproceduresp_money(s_mo
4、neyinnumber,s_accountnoinchar)isx_moneynumber(10,2);toolongexception;beginselectmoneyintox—moneyfromdepositorwhereaccountno=s_accountno;ifs_money+x_money<0thenraisetoolong;elseupdatedepositorsetmoney=money+s_moneywhereaccountno=s_accountno;endif;exceptionwhentoolongthendbms
5、_output.put_line('您的余额不足!');whenothersthennull;endsp_money;触发器:createorreplacetriggeraccount_triggerafterupdateondepositorforeachrowdeclare——localvariableshereflagint;beginif(:old.money-:new.money)<0thenflag:=l;elsif(:old.money-:new.money)>0then•flag:=-l;endif;insertintoacc
6、ount_asscessvalues(:old.accountno,flag,(:new.money-:old.money));<>null;endaccount—trigger;2.(1)编写一个名力“sp_max”的存储过程,它能给出成绩最高的一位学生姓名、性别、所学专业、成绩,写出创建存储过程及执行存储过程。以emp表为例:selectename,job,salfromempwheresal=(selectmax(sal)fromemp)(2)编写一个名为“sp_ZOng”的存储过程,它能根据学生姓名统计该学生的总成绩并能将
7、成绩返回给调用者,写出创建存储过程及执行存储过程。createorreplaceproceduresp_sql(nameinvarchar2,v_saloutnumber)isbeginselectsalintov_salfromempwhereename=name;endsp_sql;declarenamevarchar2(20):='MARTIN';salnumber;beginsp_sql(name,sal);dbms_output.put_line(sal);end;(1)编写一个名为“sp_wdate”存储过程,它能根据课程号将该课
8、程的考核成绩提高10%,写出创建存储过程及执行存储过程。createorreplaceproceduresp_update(c_empnoinnumber,c_sa
此文档下载收益归作者所有