存储过程的应用

存储过程的应用

ID:28042171

大小:47.50 KB

页数:4页

时间:2018-12-07

存储过程的应用_第1页
存储过程的应用_第2页
存储过程的应用_第3页
存储过程的应用_第4页
资源描述:

《存储过程的应用》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库

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

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。