- 1、本文档共4页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
存储过程的应用
存储过程练习题
版本1.0
1. 现有以下2张表,存取款是在银行里的交易情况,储户动态信息表是储户在银行的存款金额,现在创建一个触发器,实现当我们在存取款中取钱或存钱时,储户动态信息表中存款金额也要发生相应的改变,当存钱时就加,取钱时就减。当cke0时透支时,就不给取款
a. create table 存取款表
(金额money,--存取金额
标志int,--存取标志1为存,0为取
账号char(15),--账号
)
create table account_asscess(accountno char(15)not null,flag int,money number(10,2))
create table 储户动态信息表
(账号char(15)primarykey 存款额money)
create table depositor(accountno char(15)primary key,money number(10,2)not null)
create or replace trigger account_trigger
after update on depositor
for each row
declare
-- local variables here
flag int;
begin
if :new.money:old.money then
flag:=1;
elsif :new.money:old.money then
flag:=0;
if :new.money0 then
goto over;
end if;
end if;
insert into account_asscess values(:new.accountno,flag,(:new.money-:old.money));
over
null;
end account_trigger;
insert into depositor values(123456789012345,1000)
可以透支的:
create or replace procedure sp_money(s_money in number,s_accountno in char) is
x_money number(10,2);
toolong exception;
begin
select money into x_money from depositor where accountno=s_accountno;
if s_money+x_money0 then
raise toolong;
else
update depositor set money = money + s_money where accountno=s_accountno;
end if;
exception
when toolong then
dbms_output.put_line(您的余额不足!);
when others then
null;
end sp_money;
触发器:
create or replace trigger account_trigger
after update on depositor
for each row
declare
-- local variables here
flag int;
begin
if (:old.money-:new.money)0 then
flag:=1;
elsif (:old.money-:new.money)0 then
flag:=-1;
end if;
insert into account_asscess values(:old.accountno,flag,(:new.money-:old.money));
over
null;
end account_trigger;
(1)编写一个名为“sp_max”的存储过程,它能给出成绩最高的一位学生姓名、性别、所学专业、成绩,写出创建存储过程及执行存储过程。
以emp表为例:
select ename,job,sal from emp where sal=(select max(sal) from emp)
(2)编写一个名为“sp_zong”的存储过程,它能根据学生姓名统计该学生的总成绩并能将成绩返回给调用者,写
您可能关注的文档
最近下载
- 基于STM32单片机的太阳能寻光自动追光系统的设计.docx
- 云南省第一人民医院肺血管介入诊疗知情同意书(2022年-2023年).pdf VIP
- 脊柱影像 脊柱四肢成人脊柱MR表现 (医学影像检查技术课件).pptx
- 动物医学毕业论文..doc
- 2024年度山东中国铁路济南局集团限公司招聘普通高校本科及以上学历毕业生193人(三)公开引进高层次人才和急需紧缺人才笔试参考题库(共500题)答案详解版.docx
- 中国科技期刊卓越行动计划入选期刊目录.docx
- gb1231-2016螺栓扭矩标准.pdf
- 湘教版七年级美术(上册)全册教学案.docx
- 七年级语文上册统编版:21_女娲造人-学习任务单 (1).docx
- 2022年部编版小学语文二年级下册期末试卷含答案(共十套).docx VIP
文档评论(0)