Skip to content

Commit c0529b0

Browse files
💬Generate LLM translations (#2109)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: z <[email protected]>
1 parent 3bde528 commit c0529b0

File tree

1 file changed

+58
-23
lines changed

1 file changed

+58
-23
lines changed

docs/cn/sql-reference/10-sql-commands/00-ddl/15-variable/set-variable.md

Lines changed: 58 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,53 +5,88 @@ import FunctionDescription from '@site/src/components/FunctionDescription';
55

66
<FunctionDescription description="Introduced or updated: v1.2.609"/>
77

8-
设置会话中一个或多个 SQL 变量的值。这些值可以是简单常量、表达式、查询结果或数据库对象。
8+
设置会话中一个或多个 SQL 变量的值。这些值可以是简单常量、表达式、查询结果或数据库对象。变量在会话期间持续存在,并可在后续查询中使用。
99

10-
## 语法
10+
## Syntax
1111

1212
```sql
13-
-- 设置一个变量
13+
-- Set one variable
1414
SET VARIABLE <variable_name> = <expression>
1515

16-
-- 设置多个变量
16+
-- Set more than one variable
1717
SET VARIABLE (<variable1>, <variable2>, ...) = (<expression1>, <expression2>, ...)
18+
19+
-- Set multiple variables from a query result
20+
SET VARIABLE (<variable1>, <variable2>, ...) = <query>
1821
```
1922

20-
## 示例
23+
## Accessing Variables
24+
25+
可以使用美元符号语法访问变量:`$variable_name`
2126

22-
以下示例设置单个变量:
27+
## Examples
28+
29+
### Setting a Single Variable
2330

2431
```sql
25-
-- 将变量 a 设置为字符串 'databend'
32+
-- Sets variable a to the string 'databend'
2633
SET VARIABLE a = 'databend';
34+
35+
-- Access the variable
36+
SELECT $a;
37+
┌─────────┐
38+
│ $a │
39+
├─────────┤
40+
│ databend│
41+
└─────────┘
2742
```
2843

29-
以下示例设置一个包含表名的变量,并使用 IDENTIFIER 基于该变量动态查询表:
44+
### Setting Multiple Variables
3045

3146
```sql
32-
CREATE TABLE monthly_sales(empid INT, amount INT, month TEXT) AS SELECT 1, 2, '3';
33-
34-
-- 将变量 't' 设置为表 'monthly_sales' 的名称
35-
SET VARIABLE t = 'monthly_sales';
36-
37-
-- 使用 IDENTIFIER 动态引用存储在变量 't' 中的表名
38-
SELECT * FROM IDENTIFIER($t);
47+
-- Sets variable x to 'xx' and y to 'yy'
48+
SET VARIABLE (x, y) = ('xx', 'yy');
3949

40-
empid|amount|month|
41-
-----+------+-----+
42-
1| 2|3 |
50+
-- Access multiple variables
51+
SELECT $x, $y;
52+
┌────┬────┐
53+
│ $x │ $y │
54+
├────┼────┤
55+
│ xx │ yy │
56+
└────┴────┘
4357
```
4458

45-
以下示例在单个语句中从查询设置多个变量。查询必须只返回一行,且值的数量与要设置的变量数量相同。
59+
### Setting Variables from Query Results
4660

4761
```sql
48-
-- 将变量 a 设置为 3,b 设置为 55
62+
-- Sets variable a to 3 and b to 55
4963
SET VARIABLE (a, b) = (SELECT 3, 55);
64+
65+
-- Access the variables
66+
SELECT $a, $b;
67+
┌────┬────┐
68+
│ $a │ $b │
69+
├────┼────┤
70+
355
71+
└────┴────┘
5072
```
5173

52-
以下示例将多个变量设置为常量:
74+
### Dynamic Table References
75+
76+
变量可以与 `IDENTIFIER()` 函数一起使用,以动态引用数据库对象:
5377

5478
```sql
55-
-- 将变量 x 设置为 'xx',y 设置为 'yy'
56-
SET VARIABLE (x, y) = ('xx', 'yy');
79+
-- Create a sample table
80+
CREATE OR REPLACE TABLE monthly_sales(empid INT, amount INT, month TEXT) AS SELECT 1, 2, '3';
81+
82+
-- Set a variable 't' to the name of the table 'monthly_sales'
83+
SET VARIABLE t = 'monthly_sales';
84+
85+
-- Use IDENTIFIER to dynamically reference the table name stored in the variable 't'
86+
SELECT * FROM IDENTIFIER($t);
87+
┌───────┬────────┬───────┐
88+
│ empid │ amount │ month │
89+
├───────┼────────┼───────┤
90+
123
91+
└───────┴────────┴───────┘
5792
```

0 commit comments

Comments
 (0)