Oracle 数据库存储过程
2016-04-16 18:19
399 查看
1、银行转账
2、学员信息
use master go if exists (select * from sysdatabases where name ='BankDB' ) drop database BankDB go create database BankDB go use BankDB go create table bank ( name nvarchar(50) primary key, money int not null ) go insert into bank values ('张三',1000) insert into bank values ('李四',0) insert into bank values ('王五',15000) insert into bank values ('赵六',1000) insert into bank values ('孙七',8000) select * from bank go if exists (select * from sysobjects where name ='proc_bank' ) drop proc proc_bank go create proc proc_bank @from nvarchar(50), @to nvarchar(50), @money int as if(@money<0) begin raiserror('不可以小于0',16,1) end declare @err int set @err = 0 begin transaction update bank set money = money-@money where name = @from set @err += @@ERROR update bank set money = money+@money where name = @to set @err += @@ERROR if(@err >0) rollback transaction else commit transaction go exec proc_bank '张三','李四',1000 go
2、学员信息
use master go if exists(select * from sysdatabases where name = 'MySchool') drop database MySchool go create database MySchool go use MySchool go create table Stu ( id int primary key identity(1,1), gradeId nvarchar(50) not null, name nvarchar(50) not null unique, sex bit not null, age int not null check (age>=0 and age <=100), hobby nvarchar(50) not null ) insert into Stu values(1,'张三',0,10,'篮球') insert into Stu values(2,'李四',1,20,'篮球') insert into Stu values(3,'王五',0,55,'篮球') insert into Stu values(2,'赵六',1,44,'篮球') insert into Stu values(1,'孙七',0,33,'篮球') go select * from Stu go --要求全部使用存储过程 --1.查询全部学员信息(不带任何参数) if exists(select * from sysobjects where name = 'Proc_Stu') drop proc Proc_Stu go create proc Proc_Stu as select * from Stu go exec Proc_Stu --2.根据学号查询学员信息(带输入参数) if exists(select * from sysobjects where name = 'Proc_Stu') drop proc Proc_Stu go create proc Proc_Stu @id int as select * from Stu where id = @id go exec Proc_Stu 1 --3.根据学号查询学员年龄(使用带输出参数 print @age) if exists(select * from sysobjects where name = 'Proc_Stu') drop proc Proc_Stu go create proc Proc_Stu @id int, @age int output as select @age = age from Stu where id = @id go declare @age int exec Proc_Stu 1,@age output print @age
相关文章推荐
- oracle timestamp与字符串转换
- oracle centos 静默安装
- python3.4连接和读取oracle数据表
- oracle学习 第三章 常用的SQL*PLUS命令 ——01
- .net(C#)访问Oracle数据库的几种免安装组件的对比
- PowerDesigner 连接oracle数据库
- oracle用户默认表空间
- 在centos6.7下安装oracle11gR2的示例数据库
- oracle学习总结4
- 本地windows下PHP连接远程oracle遇到的诸多问题
- rman备份脚本
- Oracle的硬解析和软解析
- 关于根据oracle字段长度更新字段值
- oracle中expdp和impdp(数据泵)
- oracle中的schema
- ORACLE数据库用户账号处于expired状态如何处理
- Oracle操作
- Oracle中的where部分的各个条件的执行顺序(右->左)
- Oracle查询表所属用户
- [备忘]CentOS 7.2 Oracle JDK安装配置