Dynamic SQL

NuoDB SQL supports the use of SQL statements that are defined and compiled at runtime for use in SQL stored procedures or user defined functions (UDFs

Syntax

EXECUTE IMMEDIATE sql_statement
[ INTO target_var [ , target_var ] ... ]
[ USING VALUES input_var [ , input_var ] ... ]

Description

Dynamic SQL and the EXECUTE IMMEDIATE statement allow any SQL statement to be executed within a SQL stored procedure , trigger or UDF.

EXECUTE IMMEDIATE allows SQL statements to be defined and compiled at runtime, thereby allowing the SQL statement to be dynamically built at execution time by substituting parameter values or concatenating text strings. Concatenating text strings allows building SQL statements that select from different tables and columns. The EXECUTE IMMEDIATE statement supports the following capabilities:

Note: NuoDB does not support the INTO parameter with returning column values from a SELECT statement. However, the variable assignment statement can be used to implement this functionality.

When writing dynamic SQL, NULL values need to be considered. This is true of SQL statements in general, not just dynamic SQL. For example, an SQL statement such as WHERE column = value will never be equal if value is NULL.

SQL statements that contain quoted literals also need to be considered when constructing dynamic SQL. NuoDB supports a function that will automatically escape quotes within a value. See QUOTENAME.

Parameters

Examples