Skip to content

Commit 8809e64

Browse files
committed
Revert "Revert "added procedure commands""
This reverts commit 4d6509f.
1 parent 9cc90cc commit 8809e64

File tree

6 files changed

+158
-0
lines changed

6 files changed

+158
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"label": "Procedure"
3+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
title: CALL PROCEDURE
3+
---
4+
import FunctionDescription from '@site/src/components/FunctionDescription';
5+
6+
<FunctionDescription description="Introduced or updated: v1.2.637"/>
7+
8+
Executes a stored procedure by calling its name, optionally passing arguments if the procedure requires them.
9+
10+
## Syntax
11+
12+
```sql
13+
CALL PROCEDURE <procedure_name>([<argument1>, <argument2>, ...])
14+
```
15+
16+
## Examples
17+
18+
This example demonstrates how to create and call a stored procedure that converts a weight from kilograms (kg) to pounds (lb):
19+
20+
```sql
21+
CREATE PROCEDURE convert_kg_to_lb(kg DECIMAL(4, 2))
22+
RETURNS DECIMAL(10, 2)
23+
LANGUAGE SQL
24+
COMMENT = 'Converts kilograms to pounds'
25+
AS $$
26+
BEGIN
27+
RETURN kg * 2.20462;
28+
END;
29+
$$;
30+
31+
CALL PROCEDURE convert_kg_to_lb(10.00);
32+
33+
┌────────────┐
34+
│ Result │
35+
├────────────┤
36+
22.0462000
37+
└────────────┘
38+
```
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
title: CREATE PROCEDURE
3+
---
4+
import FunctionDescription from '@site/src/components/FunctionDescription';
5+
6+
<FunctionDescription description="Introduced or updated: v1.2.637"/>
7+
8+
Defines a stored procedure that executes SQL operations and returns a result.
9+
10+
## Syntax
11+
12+
```sql
13+
CREATE PROCEDURE <procedure_name>(<parameter_name> <data_type>, ...)
14+
RETURNS <return_data_type> [NOT NULL]
15+
LANGUAGE <language>
16+
[ COMMENT '<comment>' ]
17+
AS $$
18+
BEGIN
19+
<procedure_body>
20+
RETURN <return_value>;
21+
END;
22+
$$;
23+
```
24+
25+
| Parameter | Description |
26+
|-----------------------------------------|---------------------------------------------------------------------------------------------------------------------------|
27+
| `<procedure_name>` | Name of the procedure. |
28+
| `<parameter_name> <data_type>` | Input parameters (optional), each with a specified data type. Multiple parameters can be defined and separated by commas. |
29+
| `RETURNS <return_data_type> [NOT NULL]` | Specifies the data type of the return value. `NOT NULL` ensures the returned value cannot be NULL. |
30+
| `LANGUAGE` | Specifies the language in which the procedure body is written. Currently, only `SQL` is supported. |
31+
| `COMMENT` | Optional text describing the procedure. |
32+
| `AS ...` | Encloses the procedure body, which contains SQL statements, variable declarations, loops, and a RETURN statement. |
33+
34+
## Examples
35+
36+
This example defines a stored procedure that converts weight from kilograms (kg) to pounds (lb):
37+
38+
```sql
39+
CREATE PROCEDURE convert_kg_to_lb(kg DECIMAL(4, 2))
40+
RETURNS DECIMAL(10, 2)
41+
LANGUAGE SQL
42+
COMMENT = 'Converts kilograms to pounds'
43+
AS $$
44+
BEGIN
45+
RETURN kg * 2.20462;
46+
END;
47+
$$;
48+
```
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
title: DROP PROCEDURE
3+
---
4+
import FunctionDescription from '@site/src/components/FunctionDescription';
5+
6+
<FunctionDescription description="Introduced or updated: v1.2.637"/>
7+
8+
Deletes an existing stored procedure.
9+
10+
## Syntax
11+
12+
```sql
13+
DROP PROCEDURE <procedure_name>([<parameter_type1>, <parameter_type2>, ...])
14+
```
15+
16+
- If a procedure has no parameters, use empty parentheses: `DROP PROCEDURE <procedure_name>()`;
17+
- For procedures with parameters, specify the exact types to avoid errors.
18+
19+
## Examples
20+
21+
This example creates and then drops a stored procedure:
22+
23+
```sql
24+
CREATE PROCEDURE convert_kg_to_lb(kg DECIMAL(4, 2))
25+
RETURNS DECIMAL(10, 2)
26+
LANGUAGE SQL
27+
COMMENT = 'Converts kilograms to pounds'
28+
AS $$
29+
BEGIN
30+
RETURN kg * 2.20462;
31+
END;
32+
$$;
33+
34+
DROP PROCEDURE convert_kg_to_lb(Decimal(4, 2));
35+
```
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: Procedure
3+
---
4+
import IndexOverviewList from '@site/src/components/IndexOverviewList';
5+
6+
This page provides reference information for the procedure-related commands in Databend.
7+
8+
<IndexOverviewList />
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
title: SHOW PROCEDURES
3+
---
4+
import FunctionDescription from '@site/src/components/FunctionDescription';
5+
6+
<FunctionDescription description="Introduced or updated: v1.2.637"/>
7+
8+
Returns a list of all stored procedures in the system.
9+
10+
## Syntax
11+
12+
```sql
13+
SHOW PROCEDURES
14+
```
15+
16+
## Examples
17+
18+
```sql
19+
SHOW PROCEDURES;
20+
21+
┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
22+
│ name │ procedure_id │ arguments │ comment │ description │ created_on │
23+
├──────────────────┼──────────────┼─────────────────────────────────────────────────────────┼──────────────────────────────┼────────────────────────┼────────────────────────────┤
24+
│ convert_kg_to_lb │ 2104 │ convert_kg_to_lb(Decimal(4, 2)) RETURN (Decimal(10, 2)) │ Converts kilograms to pounds │ user-defined procedure │ 2024-11-07 04:12:25.243143
25+
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
26+
```

0 commit comments

Comments
 (0)