SqlServer和Oracle中一些常用的sql语句6 存储过程
--不带参数的存储过程
CREATE procedure proc_sql1
as
begin
declare @i int
set @i=0
while @i<26
begin
print char(ascii('a')+@i)+'的ASCII码是:'+cast(ascii('a')+@i as varchar(50))
set @i=@i+1
end
end execute proc_sql1 --数据查询不带参数的储存过程
create procedure proc_sql4
as
begin
select * from 职工 where 姓名 like '%张%'
select * from 仓库 where 仓库号 in(
select 仓库号 from 职工 where 姓名 like '%张%' )
end
go
execute proc_sql4 --带有输入参数的存储过程
create proc proc_sql5
@x1 int,
@x2 int,
@x3 int
as
begin
declare @max int
if @x1>@x2
set @max=@x1
else
set @max=@x2 if @x3>@max
set @max=@x3 print '3个数中最大的数是:'+cast(@max as varchar(50))
end execute proc_sql5 15,28,39 --带有输入参数的查询存储过程
create proc proc_sql7
@mingz int,
@maxgz int
as
select * from 职工 where 工资 between @mingz and @maxgz execute proc_sql7 1500,1800 --带输入和输出参数的存储过程
create proc proc_sql9
@changkuhao varchar(50),
@maxgz int output,
@avggz real output
as
begin
select * from 职工 where 仓库号=@changkuhao
select @maxgz=max(工资) from 职工 where 仓库号=@changkuhao
select @avggz=avg(工资) from 职工 where 仓库号=@changkuhao
end --显示指定仓库号的职工信息及该仓库号的最大工资和平均工资
declare @x1 int,@x2 real
execute proc_sql9 'wh1',@x1 output,@x2 output
select @x1 as wh1职工最大工资,@x2 as wh1职工平均工资 ---带登陆判断功能的存储过程
create proc proc_sql10
@hyuser varchar(50),
@hypwd varchar(50)
as
begin
declare @msg varchar(50)
if @hyuser='hystu1'
begin
if @hypwd='111'
set @msg='用户名与密码正确,成功登录!'
else
set @msg='密码不正确,请重新输入!'
end
else if @hyuser='hystu2'
begin
if @hypwd='222'
set @msg='用户名与密码正确,成功登录!'
else
set @msg='密码不正确,请重新输入!'
end
else if @hyuser='hystu3'
begin
if @hypwd='333'
set @msg='用户名与密码正确,成功登录!'
else
set @msg='密码不正确,请重新输入!'
end
else
set @msg='用户名不正确,请重新输入!'
print @msg
end execute proc_sql10 'hystu1','111' --带有判断条件的插入功能的存储过程
create proc proc_sql13
@zghao varchar(30),
@ckhao varchar(30),
@sname varchar(50),
@sex varchar(10),
@gz int
as
begin
if exists(select * from 职工 where 职工号=@zghao)
print '该职工已存在,请重新输入职工号!'
else
begin
if exists(select * from 仓库 where 仓库号=@ckhao)
begin
insert into 职工(职工号,仓库号,姓名,性别,工资) values(@zghao,@ckhao,@sname,@sex,@gz)
print '成功的插入一条记录'
end
else
print '输入的仓库号不合法,请重新输入仓库号!'
end
end
GO execute proc_sql13 'zg1','wh1','张平','女',1350 execute proc_sql13 'zg42','wh11','张平','女',1350 execute proc_sql13 'zg42','wh1','张平','女',1350
SqlServer和Oracle中一些常用的sql语句6 存储过程的更多相关文章
- SqlServer和Oracle中一些常用的sql语句9 SQL优化
--SQL查询优化 尽量避免使用or,not,distinct运算符,简化连接条件 /*Or运算符*/ use db_business go select * from 仓库 where 城市='北京 ...
- SqlServer和Oracle中一些常用的sql语句5 流程控制语句
--在sql语句中 begin...end 用来设定一个程序块 相关于c#中的{} declare @yz real,@w int --声明变量 set @w=120 --为变量赋值 if @w< ...
- SqlServer和Oracle中一些常用的sql语句10 特殊应用
--482, ORACLE / SQL SERVER --订购数量超过平均值的书籍 WITH Orders_Book AS ( SELECT Book_Name, SUM(Qty) Book_Qty ...
- SqlServer和Oracle中一些常用的sql语句3 行列转换
--217, SQL SERVER SELECT Cust_Name , MAX(CASE WHEN Order_Date ='2009-08-01' THEN AR END) "2009- ...
- SqlServer和Oracle中一些常用的sql语句7 游标
declare db_cursor4 scroll cursor for select * from 供应商 --声明游标 open db_cursor4 --打开游标 fetch first fro ...
- SqlServer和Oracle中一些常用的sql语句8 触发器和事务
--创建和执行事后触发器 --更新仓库备份表中记录时自动创建数据表且插入三条记录 create trigger db_trigger1 on 仓库备份 for update as begin if E ...
- SqlServer和Oracle中一些常用的sql语句4 局部/全局变量
--把wh1仓库号中姓名含有"平"字的职工工资在原来的基础上加288 update 职工备份 set 工资=工资+288 where 仓库号='wh1' and 姓名 like ' ...
- SqlServer 获取字符串中小写字母的sql语句
SQL字符串截取(SubString) 作用:返回第一个参数中从第二个参数指定的位置开始.第三个参数指定的长度的子字符串. 有时候我们会截取字符串中的一些特殊想要的东西,大小写字母.模号.汉字.数字等 ...
- SqlServer 查看备份文件中逻辑文件信息的Sql语句
RESTORE FILELISTONLY FROM DISK = 'D:\All\DataBase\(2013-12-18)-1.bak' 用来查看备份文件中的逻辑文件信息. 相关信息:SqlServ ...
随机推荐
- Java之对象序列化和反序列化
一.对象序列化和反序列化存在的意义: 当你创建对象,只要你需要,他就一直存在,但当程序结束,对象就会消失,但是存在某种情况,如何让程序在不允许的状态,仍然保持该对象的信息.并在下次程序运行的时候使用该 ...
- Hadoop Security Authentication Terminology --Kerberos
Hadoop Security Authentication Terminology --Kerberos What is kinit? Kinit - obtain and cache Kerbe ...
- sublime2/3自总结经常使用快捷键(2的居多)
Ctrl+D 选词 (重复按快捷键,就可以继续向下同一时候选中下一个同样的文本进行同一时候编辑) Ctrl+鼠标左键 能够同一时候选择要编辑的多处文本 Shift+鼠标右键(或使用鼠标中键)能够用鼠标 ...
- reason: 'unable to dequeue a cell with identifier Cell
今天在cell重用的时候出现一下错误 reason: 'unable to dequeue a cell with identifier Cell - must register ...
- codeblock快捷键
一款开源的C/C++ IDE(集成开发环境),基于wxWidgets GUI体系,跨平台支持. 从别处粘贴的,方便以后看,啦啦啦…… 编辑器 快捷键 功能 Ctrl+Z 恢复上一次操作 Ctrl+Sh ...
- Week2(9月16日):动手做个简单的例子
Part I:提问 =========================== 1.什么是ASP.NET MVC? 2.MVC的英文? 3.什么是模型? 4.什么是控制器? 5.什么是视图? 6.ASP ...
- Qt中所有类型之间的转换
1.char * 与 const char *的转换 char *ch1="hello11";const char *ch2="hello22";ch2 = c ...
- fancyBox简单入门
1. 下载 fancyBox,解压后根据需要将文件复制到网页文件夹中(建议不要更改目录结构),并在网页源码中引入相应的 css 样式和 js 文件(如果更改了目录结构,引入的时候请调整相应代码,对应它 ...
- Python 2.7 学习笔记 内置语句、函数、标准库
使用任何开发语言进行软件开发,都离不开语言提供的内置库(或Api),甚至说内置库的强大及使用是否方便都会影响大家对开发语言的选择. python语言,一样提供了很多内置的功能,可供开发时使用.主要有如 ...
- JMS和消息驱动Bean(MDB)
一.说明 本示例使用的ActiveMQ作为消息中间件,服务器为Glassfish,使用JMS发送消息,在MDB接收到消息之后做打印输出. 二.ActiveMQ安装配置 1.安装console war包 ...