SqlServer和Oracle中一些常用的sql语句6 存储过程

SqlServer和Oracle中一些常用的sql语句6 存储过程,第1张

概述--不带参数的存储过程CREATE procedure proc_sql1asbegin 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
--不带参数的存储过程CREATE procedure proc_sql1asbegin  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       endendexecute proc_sql1--数据查询不带参数的储存过程create procedure  proc_sql4asbegin   select * from 职工 where 姓名 like '%张%'   select * from 仓库 where 仓库号 in(     select 仓库号 from 职工 where 姓名 like '%张%' )endgoexecute proc_sql4--带有输入参数的存储过程create proc proc_sql5 @x1 int,@x2 int,@x3 intasbegin 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))endexecute proc_sql5 15,28,39--带有输入参数的查询存储过程create proc proc_sql7   @mingz int,@maxgz int as  select * from 职工 where 工资 between @mingz and @maxgzexecute proc_sql7 1500,1800--带输入和输出参数的存储过程create proc proc_sql9  @changkuhao varchar(50),@maxgz  int output,@avggz  real outputas begin  select * from 职工 where 仓库号=@changkuhao  select @maxgz=max(工资) from 职工 where 仓库号=@changkuhao  select @avggz=avg(工资) from 职工 where 仓库号=@changkuhaoend--显示指定仓库号的职工信息及该仓库号的最大工资和平均工资declare @x1 int,@x2 realexecute proc_sql9 'wh1',@x1 output,@x2 outputselect @x1 as wh1职工最大工资,@x2 as wh1职工平均工资---带登陆判断功能的存储过程create proc proc_sql10  @hyuser varchar(50),@hypwd  varchar(50)asbegindeclare @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 @msgendexecute proc_sql10 'hystu1','111'--带有判断条件的插入功能的存储过程create proc proc_sql13 @zghao varchar(30),@ckhao varchar(30),@sname varchar(50),@sex   varchar(10),@gz    intas 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  endGOexecute proc_sql13 'zg1','wh1','张平','女',1350execute proc_sql13 'zg42','wh11',1350
ALTER PROCEDURE [dbo].[sp_TNotePost] @blockID INT,@Title nvarchar (200),@content TEXT,@userID bigint,@ip nvarchar (50),@Result int out ASBEGIN	DECLARE @fdate date,@ID bigint,@fcontent nvarchar(200),@IErrorCount int 	BEGIN TRAN		SET @fdate = GETDATE()		--插入新帖		INSERT INTO T_Note (blockID,Title,content,userID,ip) VALUES	(@blockID,@Title,@content,@userID,@ip)		SET @IErrorCount=@IErrorCount+@@error		SET @ID = @@IDENTITY 		select @fcontent=SUBSTRING(content,100) from T_Note where ID=@ID		--更新版块信息		UPDATE T_topic SET num = num + 1,lastNoteID =@ID,lastNoteDate=@fdate,lastNoteTitle=@fcontent where blockID=@blockID		SET @IErrorCount=@IErrorCount+@@error		--更新个人其他基本信息		UPDATE T_User_Other  SET noteCount=noteCount+1,lastNoteTime=@fdate,lastNoteTitle=@fcontent where userID=@userID		SET @IErrorCount=@IErrorCount+@@errorIF @IErrorCount <> 0  --发生错误  		BEGIN  				RolLBACK TRAN  				SET @Result=0  		END  ELSE  		BEGIN  				COMMIT TRAN  				SET @Result=@ID    --执行成功  		ENDEND
总结

以上是内存溢出为你收集整理的SqlServer和Oracle中一些常用的sql语句6 存储过程全部内容,希望文章能够帮你解决SqlServer和Oracle中一些常用的sql语句6 存储过程所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/sjk/1174201.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-02
下一篇 2022-06-02

发表评论

登录后才能评论

评论列表(0条)

保存