SQL用户自定义存储过程

创建存储过程

无参存储过程

go
if exists(select * from sysobjects where name='存储过程名')
   drop  procedure 存储过程名
--创建存储过程
create procedure 存储过程名
as
   内容体
 

有参存储过程

在这里插入代码片
go
if exists(select * from sysobjects where name='存储过程名')
   drop  procedure 存储过程名
--创建存储过程
create procedure 存储过程名(
    @变量名1  int      --输入参数,用于接收商品类型名称as
   内容体
   [select * from where id=@变量名1]
 

调用存储过程

--无参
exec  存储过程名  ||  execute 存储过程名
--有参
exec  存储过程名  '参数'

创建有输出参数的存储过程 :例子

--判重
go
if exists(select * from sysobjects where name='proc_aaa')
  drop procedure  proc_aaa、
 -- 创建有输出参数的存储过程
go
create procedure proc_aaa(
  @type nvarchar(50),
  @num int output   --使用关键字声明输出参数
)
as 
select @num=COUNT(*) from  TypeTB where  TypeName=@type

***调用***
---调用
go
declare @num int
declare @type nvarchar(20)
set
@type=N'恐怖'
exec proc_aaa @type,@num output 
print @num

发布了10 篇原创文章 · 获赞 0 · 访问量 75

猜你喜欢

转载自blog.csdn.net/weixin_44719554/article/details/105123265