Help Centre › Building Processes
This article describes the RPA Database functionality to execute a non-query statement.
For a full list of available functions, please read DATABASE functions.
Description
The Execute statement function runs an INSERT, UPDATE, or DELETE statement against the database and returns the number of affected rows. This is used for data modification operations that do not return result sets.
Setting it up
To use the Execute statement function, follow these instructions:
{{popups:rpas/add:action=db-execute}}
Once on a process map:
- Navigate to the process where you would like to add the Execute statement function
- Click on the green button's drop-down (right side of the green button labelled "Process")
- On the menu that appears, click on the "+ Activity" item
- From here you can select the Execute statement option
- Click "Add" once you are done
Input parameters
| Parameter | Required | Type | Default | Description |
|---|---|---|---|---|
| Name | Yes | Text | - | The alias of a previously opened connection (from db-connect) |
| Query | Yes | Text | - | The SQL INSERT, UPDATE, or DELETE statement to execute |
| Params | No | Array | - | An array of values for parameterised queries (use %s or ? as placeholders) |
| Variable | No | Text | affected_rows | Variable name to store the number of affected rows |
Output variables
| Variable | Type | Description |
|---|---|---|
| {affected_rows} | Integer | The number of rows affected by the statement |
Errors
| Error | Description |
|---|---|
| Connection not found | No open connection exists with the specified name |
| Query error | The SQL statement contains a syntax error or references invalid objects |
Tips
- Use the params array for parameterised queries to prevent SQL injection
- Check the affected_rows output to verify the expected number of rows were modified
- Wrap multiple execute statements in a transaction (db-begin-transaction / db-commit) for atomicity