(2.2)DDL增强功能-函数与存储过程

1.存储过程

  (1)基本形式

[sql]  view plain  copy
 
  1. create proc | procedure pro_name  
  2.     [{@参数数据类型} [=默认值] [output],  --加上output就代表是地址传递(即会从调用接收,也会输出给调用)
  3.      {@参数数据类型} [=默认值] [output],  
  4.      ....  
  5.     ]  
  6. as  
  7.     SQL_statements  

  (2)实例演示

--判断过程是否存在
IF
OBJECT_ID('getArea') is not null BEGIN drop procedure getArea END GO --创建存储过程 create procedure getArea @shopId nvarchar(64) , @area nvarchar(32) output as begin print @area if (@shopId is not null and @shopId <> '') begin select @area= 2 end else begin set @area = '' end end --声明变量 declare @a varchar(20); set @a='1'
--执行存储过程
execute getArea '2010315', @a output;

--输出验证结果
print @a ; GO

猜你喜欢

转载自www.cnblogs.com/gered/p/9117948.html