> ## Documentation Index
> Fetch the complete documentation index at: https://docs.oration.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Database

> Query or update database records

The **Database** node executes SQL queries or stored procedures against a configured database connection and stores the results for use in the flow.

## Behavior

* Connects to a pre-configured database using the connection ID
* Executes parameterized queries to prevent SQL injection
* Stores results in the configured variable name
* Routes to `Success`, `Error`, or `No Results` based on the outcome

## Configuration

### Connection & operation

| Parameter      | Type   | Default   | Options                                                 | Description                                               |
| -------------- | ------ | --------- | ------------------------------------------------------- | --------------------------------------------------------- |
| `connectionId` | string | `""`      | —                                                       | Database connection ID (configured in workspace settings) |
| `operation`    | enum   | `"query"` | `query`, `insert`, `update`, `delete`, `call_procedure` | Database operation type                                   |
| `query`        | string | `""`      | —                                                       | SQL query or stored procedure name                        |
| `timeout`      | number | `10000`   | 1,000–60,000                                            | Query timeout in milliseconds                             |

### Parameters

Each entry in the `parameters` array:

| Field   | Type   | Description                                             |
| ------- | ------ | ------------------------------------------------------- |
| `name`  | string | Parameter name (maps to a placeholder in the query)     |
| `value` | string | Parameter value. Supports `{{variable}}` interpolation. |
| `type`  | enum   | Data type: `string`, `number`, `boolean`, `date`        |

### Results

| Parameter        | Type    | Default       | Description                                   |
| ---------------- | ------- | ------------- | --------------------------------------------- |
| `resultVariable` | string  | `"db_result"` | Variable name to store query results          |
| `singleRow`      | boolean | `false`       | Return only the first row instead of all rows |

## Output handles

| Handle         | Description                                            |
| -------------- | ------------------------------------------------------ |
| **Success**    | Query executed successfully with results               |
| **Error**      | Query failed (connection error, syntax error, timeout) |
| **No Results** | Query executed but returned no rows                    |

## Output variables

| Variable    | Type   | Description                         |
| ----------- | ------ | ----------------------------------- |
| `rows`      | array  | Array of result rows                |
| `row_count` | number | Number of rows returned or affected |

## Example

Look up a customer by account number:

```sql theme={null}
SELECT name, email, tier FROM customers WHERE account_id = @account_id
```

Parameters:

| Name         | Value        | Type     |
| ------------ | ------------ | -------- |
| `account_id` | `{{digits}}` | `string` |

## Use cases

<AccordionGroup>
  <Accordion title="Account verification">
    After Collect Digits, query the database for the account. On `DB.NO_RESULTS`, play "Account not found" and retry. On success, greet the customer by name.
  </Accordion>

  <Accordion title="Call logging">
    Use the `insert` operation to log call details (caller ID, timestamp, department) into a calls table at the end of the flow.
  </Accordion>

  <Accordion title="Stored procedure">
    Set `operation` to `call_procedure` to execute complex business logic like credit checks or eligibility verification.
  </Accordion>
</AccordionGroup>
