存储过程的应用.doc

  1. 1、本文档共4页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 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”的存储过程,它能根据学生姓名统计该学生的总成绩并能将成绩返回给调用者,写

文档评论(0)

haihang2017 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档