码迷,mamicode.com
首页 > 数据库 > 详细

SQL中declare申明变量

时间:2014-10-06 11:06:20      阅读:227      评论:0      收藏:0      [点我收藏+]

标签:使用   ar   strong   sp   div   art   c   on   r   

在sql语句中加入?变量。

declare @local_variable data_type

声明时须要指定变量的类型,

能够使用set和select对变量进行赋值,

在sql语句中就能够使用@local_variable来调用变量

 

声明中能够提供值,否则声明之后全部变量将初始化为NULL。

 

比如:declare @id int

         declare @id int = 3

         set @id=2

         select id

         select @id = column_id from table where column_user = ‘ABC‘

SQL中declare申明变量

标签:使用   ar   strong   sp   div   art   c   on   r   

原文地址:http://www.cnblogs.com/yxwkf/p/4007931.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!