-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--- | ||
title: 全局变量和局部变量 | ||
author: Lee | ||
--- | ||
|
||
## 局部变量 | ||
|
||
局部变量为 `@` 开头 | ||
|
||
### 声明一个局部变量 `i`,类型为 `int` 给变量赋值 `1` | ||
|
||
```sql | ||
DECLARE @i int | ||
set @i = 1 | ||
``` | ||
|
||
### 声明一个整形变量,给变量赋值,判断改变量是奇数还是偶数 | ||
|
||
```sql | ||
DECLARE @i int | ||
set @i = 5 | ||
if @i % 2=0 | ||
begin | ||
print '我是偶数'; | ||
end | ||
else | ||
begin print '我是奇数'; | ||
end | ||
``` | ||
|
||
### 生成字符串类型然后输出 | ||
|
||
```sql | ||
DECLARE @i1 varchar(30) | ||
DECLARE @asd varchar(20) | ||
set @i1 = 'hello' | ||
set @asd = 'sql' | ||
print @i1 + @asd | ||
``` | ||
|
||
## 全局变量 | ||
|
||
全局变量由系统提供,以 `@@` 开头 | ||
|
||
### 全局变量的例子 | ||
|
||
```sql | ||
print @@version | ||
print @@language | ||
print @@servername | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
title: 11.变量 | ||
index: false | ||
author: Lee | ||
--- | ||
|
||
电脑端在左侧-侧边栏查看文档,手机端点击左上角`菜单` |