Skip to content

Commit

Permalink
docs(sql): 变量
Browse files Browse the repository at this point in the history
  • Loading branch information
Leetfs committed Oct 22, 2024
1 parent 9f4440f commit d6d0d83
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
51 changes: 51 additions & 0 deletions docs/sql/11/1.md
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
```
7 changes: 7 additions & 0 deletions docs/sql/11/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: 11.变量
index: false
author: Lee
---

电脑端在左侧-侧边栏查看文档,手机端点击左上角`菜单`

0 comments on commit d6d0d83

Please sign in to comment.