DATABASE Execute statement function

Execute an INSERT, UPDATE, or DELETE statement and return the affected row count.

Help CentreBuilding 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:

  1. Navigate to the process where you would like to add the Execute statement function
  2. Click on the green button's drop-down (right side of the green button labelled "Process")
  3. On the menu that appears, click on the "+ Activity" item
  4. From here you can select the Execute statement option
  5. Click "Add" once you are done

Input parameters

ParameterRequiredTypeDefaultDescription
NameYesText-The alias of a previously opened connection (from db-connect)
QueryYesText-The SQL INSERT, UPDATE, or DELETE statement to execute
ParamsNoArray-An array of values for parameterised queries (use %s or ? as placeholders)
VariableNoTextaffected_rowsVariable name to store the number of affected rows

Output variables

VariableTypeDescription
{affected_rows}IntegerThe number of rows affected by the statement

Errors

ErrorDescription
Connection not foundNo open connection exists with the specified name
Query errorThe 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

Related functions

See it working on your own data

Everything documented here ships with the platform – try the document tools free, or go live in 7 days.