Skip to main content
Data flows are procedural control-flow blocks that execute multiple SQL statements sequentially as a single unit in the Ocient® System. You use data flows to build multi-step workflows entirely within the database, eliminating the need for external orchestration tools. Data flows support two modes.
  • Void data flow — Executes statements for side effects such as creating tables, inserting data, or performing cleanup. A void data flow does not return a result set.
  • Query data flow — Executes statements and returns a result set using a RETURN SELECT statement.

Use Cases

Data flows are useful for these scenarios:

Syntax

This code block shows the complete syntax for data flows.
SQL
A void data flow requires at least one statement in its body. A query data flow can consist of only a RETURN SELECT statement with no preceding statements. The <initial_statement_list> and <statement_list> placeholders represent the following elements.

Initial Statement List (<initial_statement_list>)

Appears at the top level of the data flow body and accepts declarations and flow statements. You can use DECLARE statements only in this list, not inside loops, IF blocks, or a FINALLY clause.

Statement List (<statement_list>)

Appears inside loops, IF branches, and FINALLY clauses. Supports the same elements as the <initial_statement_list> except for the DECLARE element. The following table describes other structural elements.

Temporary Tables

Temporary tables use a # prefix in their names, and the database scopes them to the data flow block. The database automatically drops temporary tables when the data flow completes, so you do not need an explicit DROP TABLE SQL statement in a FINALLY clause. Syntax
SQL
Example This example creates a temporary table with the # prefix and uses it for intermediate processing. The database drops the temporary table automatically when the data flow completes.
SQL

BEGIN DATAFLOW

A void data flow executes one or more statements for their side effects. This data flow does not return a result set. Syntax
SQL
Example This example creates a temporary table (indicated by the # prefix), filters and stages data, and loads it into a final table. The database drops the temporary table automatically when the data flow completes.
SQL

BEGIN QUERY DATAFLOW

A query data flow executes statements and returns a result set. The RETURN SELECT statement must appear after all other statements and before the optional FINALLY clause. Syntax
SQL
Example This example declares the total variable, assigns it the row count from the orders table, and returns the result.
SQL

DECLARE

Declares a script variable with a specified data type and an optional initial value. You can use DECLARE statements only at the top level of the data flow body, not inside loops, IF clauses, or FINALLY clauses. Syntax
SQL
Parameters Example This example declares variables with different data types and initialization options and returns their values. The counter variable has the BIGINT type and 0 as the default value. The name variable has the VARCHAR type and default as the default string. Also, the threshold variable has the DOUBLE type and a non-NULL value with 0.95 as the default value.
SQL

Supported Variable Data Types

This table lists all data types supported for data flow variables. For details on Ocient data types, see Data Types. Type synonyms: CHAR and VARCHAR map to STRING. INTEGER maps to INT. TINYINT maps to BYTE.
Data flow variables do not support the VARBINARY, MATRIX, and FUNCTION data types.
You must initialize container variables (ARRAY and TUPLE) before use. Referencing an uninitialized container variable in an expression produces a runtime error.

SET

Assigns a new value to a previously declared variable. Syntax
SQL
The expression can be a literal, an arithmetic expression, or a scalar subquery. Example This example assigns a variable using an arithmetic expression and then reassigns it using a scalar subquery.
SQL
Output: 18

WHILE

Repeats a block of statements while a condition evaluates to true. You can use the optional MAX ITERATIONS clause to set an upper bound on the number of iterations. Syntax
SQL
Parameters Example This example uses a WHILE loop with the MAX ITERATIONS clause to sum integers from one to 10.
SQL

IF, ELSEIF, and ELSE

Executes statements conditionally. The data flow evaluates conditions in order and executes the first matching branch. You can chain zero or more ELSEIF clauses. The optional ELSE clause executes if no condition matches. Each branch contains a statement list <statement_list>. Syntax
SQL
Parameters Example This example uses chained ELSEIF clauses to map a numeric value to a string label.
SQL
Output: two

FOR

Iterates using either C-style or iterator-style syntax. Both styles support the optional MAX ITERATIONS clause. The loop body contains a statement list <statement_list>.

C-Style FOR

Syntax
SQL
Parameters The increment statement executes after each iteration, including iterations that execute the CONTINUE element. Example This example uses a C-style FOR loop to sum integers from one to five.
SQL
Output: 15

Iterator-Style FOR

Iterates over the rows returned by a query. The source query must return exactly one column. Syntax
SQL
Parameters Example This example iterates over the rows returned by a query and accumulates a sum.
SQL
Output: 55

BREAK

Immediately exits the innermost enclosing loop (WHILE or FOR). In nested loops, the BREAK element exits only the innermost loop. Using the BREAK element outside a loop produces a runtime error. Syntax
SQL
Example This example exits a WHILE loop early when the counter reaches 3.
SQL
Output: 3

CONTINUE

Skips the remainder of the current loop iteration and proceeds to the next iteration. In C-style FOR loops, the increment statement still executes before the next condition check. Using the CONTINUE element outside a loop produces a runtime error. Syntax
SQL
Example This example skips the iteration where @i equals 3, so the sum excludes that value.
SQL
Output: 12 (1 + 2 + 4 + 5; skips the iteration where @i = 3)

RAISE

Throws a user-defined error message and aborts the data flow. If the FINALLY clause is present, the database executes it before the error propagates. Syntax
SQL
Parameters Example This example checks the row count in a staging table and raises an error if the table contains no records.
SQL

TRY and EXCEPTION WHEN

Catches errors raised by statements in a TRY element. You define one or more EXCEPTION WHEN handlers that match the specific SQLSTATE code or all errors using the OTHERS string. Inside a handler, the @SQLERRM and @SQLSTATE variables expose the caught error message and SQLSTATE code. Both the TRY body and each handler contain a statement list <statement_list>. Syntax
SQL
Parameters Example This example catches any error from an INSERT SQL statement and re-raises it.
RAISE @SQLERRM forwards the original error message but not the original SQLSTATE code. The re-raised error uses a generic exception code.
SQL

FINALLY

Defines a cleanup statement that always executes when the data flow completes, regardless of whether an error occurred. Use the FINALLY clause to drop staging tables, release resources, or perform other cleanup operations that must execute even after an error. Syntax
SQL
The FINALLY clause executes even after a RAISE statement or other runtime error. Example This example uses the FINALLY clause to ensure that the data flow drops the staging table even if an error occurs during processing. Unlike temporary tables (which the database drops automatically), regular staging tables require explicit cleanup.
SQL

RETURN

Returns a result set from a query data flow. The RETURN clause must appear after all other statements and before the optional FINALLY clause. Only query data flows (using BEGIN QUERY DATAFLOW) support the RETURN clause. Syntax
SQL
Example This example filters predictions into the temporary table #filtered and returns the result set sorted by the confidence column.
SQL
Stage and Transform Data with Data Flows Build Iterative Queries with Data Flows Validate Data Before Loading with Data Flows Data Query Language (DQL) Statement Reference Data Definition Language (DDL) Statement Reference Transactions
Last modified on September 23, 2026