--
create table account(
id varchar(32) not null,
name varchar(30),
money numeric(10,2),
constraint a_pk primary key(id)
);
--历史表
select * from history;
drop table history;
create table history(
id varchar(32) not null
aid varchar(32),
dt varchar(19),
money numeric(10,2),
ty varchar(10),
constraint h_pk primary key(id),
constraint h_fk foreign key(aid) references account(id) ); --写入用户
insert into account values(sys_guid(),'Jack',100);
insert into account values(sys_guid(),'Rose',50);
select * from account;
commit;
--BDD483DA232943A2BD7AFDEAA1D13015 Jack 100
--59D6EFC956DB447CB4F9A8BB6B188CCE Rose 50
--创建过程 create or replace procedure trans(p1_id in varchar2,
p2_id in varchar2,
p_money in numeric) as
--声明一个变量
v_count integer;
--保存金额信息
v_money account.money%type;
begin
--限制p_money大于0
if p_money<=0 then
raise_application_error(-20000,'转账金额不能为0');
end if;
--先检查有没有转出的人
select count(1) into v_count from account where id=p1_id;
if v_count=0 then
raise_application_error(-20000,'转出账号不正确');
end if;
--转入的账号
select count(1) into v_count from account where id=p2_id;
if v_count=0 then
raise_application_error(-20000,'转入账号不正确');
end if;
--再检查金额情况
select money into v_money from account where id=p1_id;
--判断
if p_money>v_money then
raise_application_error(-20000,'转账金额不够');
end if;
dbms_output.put_line('开始转账');
--开始转账
--先减money
update account set money=money-p_money where id=p1_id;
--加钱
update account set money=money+p_money where id=p2_id;
--记录hist表
--转出
Insert Into History(Id,Aid,Dt,Money,Ty)
Values(Sys_Guid(),P1_Id,To_Char(Sysdate,'yyyy-mm-dd hh24:mi:ss'),
0-p_Money,'转出');
--再记录转入
Insert Into History(Id,Aid,Dt,Money,Ty)
Values(Sys_Guid(),P2_Id,To_Char(Sysdate,'yyyy-mm-dd hh24:mi:ss'),
P_Money,'转入');
dbms_output.put_line('ok');
end;
select * from account;
Select * From History; set serveroutput on;
Begin
trans('BDD483DA232943A2BD7AFDEAA1D13015','59D6EFC956DB447CB4F9A8BB6B188CCE',100);
end; commit

Oracle利用过程procedure块实现银行转账的更多相关文章

  1. Oracle利用存储过程性 实现分页

    分页的简单配置 在上一次已经说过了 这边说说怎么在存储过程中实现分页 首先建立存储过程 參考 http://www.cnblogs.com/gisdream/archive/2011/11/16/22 ...

  2. Oracle 的过程与函数

    一.过程 1 .过程创建和调用 过程 (procedure) 是一个 PL/SQL 语句块,它存储在数据字典中并可被应用程序调用.可以使用过程存储数据库中频繁使用的应用逻辑.当执行一个过程时,其语句被 ...

  3. oracle储存过程学习笔记

    转载至: https://www.2cto.com/database/201610/559389.htm 1.什么是oracle存储过程 存储过程和函数也是一种PL/SQL块,是存入数据库的PL/SQ ...

  4. oracle计算过程执行时间写法

    --在oracle写过程中很多是对数据处理,业务比较繁琐,有的需要结合job定时器使用,这样就需要知道执行过程的大概时间,不废话直接上脚本,统计单位为分钟 PROCEDURE DATA_DEAL_WI ...

  5. Oracle学习笔记--Oracle启动过程归纳整理

    Oracle 启动过程分为nomount状态mount状态open状态 每个状态下Oracle都会进行不同的操作:1.nomount状态 在$ORACLE_HOME/dbs目录下寻找参数文件 参数文件 ...

  6. centos7.3 安装oracle 详细过程

    centos7.3安装oracle详细过程1.下载Oracle安装包:linux.x64_11gR2_database_1of2.zip 和 linux.x64_11gR2_database_2of2 ...

  7. oracle 利用flashback将备库激活为read wirte(10g 及上)

    oracle 利用flashback将备库激活为read wirte(10g 及上) 环境: OS: CENTOS 6.5 X64 DB: ORACLE 10.2.0.5 主库操作: SQL> ...

  8. Oracle安装过程物理内存检查及临时temp空间不足解决办法

    物理内存 – 此先决条件将测试系统物理内存总量是否至少为 922MB (944128.0KB). 预期值 : N/A 实际值 : N/A 错误列表: – 可用物理内存 PRVF-7531 : 无法在节 ...

  9. 【PLSQL】过程procedure形参和参数

    ************************************************************************   ****原文:blog.csdn.net/clar ...

随机推荐

  1. 动态根据checkbox 增加Dom

    <%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" ...

  2. EF 事务处理 (InnoDB Engine的MySQL表也可以)

    备忘 1. 亲测(可以嵌套使用) using (TransactionScope scope = new TransactionScope()) { //操作1 XXEntities.Current. ...

  3. js判断是否安装flash

    <script type="text/javascript"> (function () { var noFlash = "你的浏览器没有安装Flash,会影 ...

  4. <httpRuntime>

    1.在webconfig中httpconfig属性只能出现一次 配置httpRunTime也可以让FileUpload上传更大的文件,不过设置太大了会因用户将大量文件传递到该服务器而导致的拒绝服务攻击 ...

  5. BestCoder 2nd Anniversary 1002 Arrange

    排除所有不符合条件后根据当前位置上下界计算, 由于前面取的数肯定在之后的区间内,所以去掉已取的个数即可. #include <iostream> #include <cstdio&g ...

  6. xaml控件样式大全(太有用了)C#

    地址:链接:http://pan.baidu.com/s/1jGlMyEi 密码:zaeg http://blog.csdn.net/lhx527099095/article/category/943 ...

  7. Java之定时任务详解

    在我们编程过程中如果需要执行一些简单的定时任务,无须做复杂的控制,我们可以考虑使用JDK中的Timer定时任务来实现.下面就其原理.实例以及Timer缺陷三个方面来解析java Timer定时器. 在 ...

  8. SlimDX的DirectSound模块

    网上SlimDX的资源很少,搜到了http://www.xukailun.me/article/238/这篇关于<SlimDX的DirectSound模块应用实战>的文章,备份下来以备不时 ...

  9. jQuery Validate 插件验证,,返回不同信息(json remote)自定义

    问题 申请账号需要确认该账号是存在 jquery.validate.js中的remote Jquery Ajax获取后台返回的Json数据后,添加自定义校验 解题思路:输入的登陆信息远程验证是否该账号 ...

  10. Train Problem I

    问题陈述: 杭州电子科技大学HANGZHOU DIANZI UNIVERSITY Online Judge Problem - 1022 问题解析: 栈(stack)的简单应用 代码详解: #incl ...