You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/en/guides/54-query/08-stored-procedure.md
+77-1Lines changed: 77 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,83 @@ A stored procedure is a set of executable commands or logic blocks stored within
6
6
7
7
## Supported Languages
8
8
9
-
**Databend currently supports [SQL Scripting](/sql/sql-reference/sql-scripting) only**. Using SQL scripting, users can define procedures with control flow constructs like loops (FOR, WHILE, REPEAT) and conditionals (IF, CASE), enabling complex logic and effective multi-step operations.
9
+
**Databend currently supports [SQL Scripting](#sql-scripting) only**. Using SQL scripting, users can define procedures with control flow constructs like loops (FOR, WHILE, REPEAT) and conditionals (IF, CASE), enabling complex logic and effective multi-step operations.
10
+
11
+
### SQL Scripting
12
+
13
+
In Databend, stored procedures support a rich set of features to allow users to define complex operations through SQL scripting. Here are the supported capabilities:
14
+
15
+
-**Variable Declaration**: Variables can be declared using the `LET` keyword, followed by the variable name, an optional type, and the initial value.
16
+
17
+
```sql title='Examples:'
18
+
LET x :=100;
19
+
```
20
+
21
+
-**Query Execution**: SQL queries can be executed within the script, and results can be stored in variables or result sets.
22
+
23
+
```sql title='Examples:'
24
+
LET result RESULTSET := SELECT * FROM t1;
25
+
```
26
+
27
+
-**Control Flow Constructs**
28
+
-**FOR Loop**: Iterates over a range or a result set.
29
+
30
+
```sql title='Examples:'
31
+
FOR i IN 1..10 DO ... END FOR;
32
+
```
33
+
34
+
-**WHILE Loop**: Executes a block of code as long as a specified condition is true.
35
+
36
+
```sql title='Examples:'
37
+
WHILE condition DO ... END WHILE;
38
+
```
39
+
40
+
-**REPEAT Loop**: Executes a block of code until a condition is met.
41
+
42
+
```sql title='Examples:'
43
+
REPEAT ... UNTIL condition END REPEAT;
44
+
```
45
+
46
+
-**LOOP**: Executes a block of code indefinitely until a `BREAK` statement is encountered.
47
+
48
+
```sql title='Examples:'
49
+
LOOP ... END LOOP;
50
+
```
51
+
52
+
-**CASE Statement**: Allows conditional execution of code blocks based on different conditions.
53
+
54
+
```sql title='Examples:'
55
+
CASE [operand]
56
+
WHEN condition1 THEN ...
57
+
WHEN condition2 THEN ...
58
+
ELSE ...
59
+
END;
60
+
```
61
+
62
+
-**IF Statement**: Executes a block of code based on a condition.
63
+
64
+
```sql title='Examples:'
65
+
IF condition THEN ...
66
+
ELSEIF condition THEN ...
67
+
ELSE ...
68
+
END IF;
69
+
```
70
+
71
+
-**RETURN**: Returns from the script with an optional value.
72
+
73
+
```sql title='Examples:'
74
+
RETURN [expr];
75
+
```
76
+
77
+
-**RETURN TABLE**: Returns from the script with a table result.
0 commit comments