You can execute any SQL statement that is supported by dynamic SQL.
To execute SQL statements, define a function that uses the SQL (DTW_SQL) language environment and contains the SQL statements in the language environment executable section of the function.
Example: An SQL function that runs an SQL SELECT statement:
%function(DTW_SQL) getOrders() { SELECT cust, custid, custorder FROM mylibrary.customers %}
Commitment Control
The SQL language environment by default runs under commitment control and follows all rules for governing commitment control.
For more information on transaction management, see Managing Transactions in a Net.Data Application.
OUT and INOUT Tables
If you specify OUT or INOUT Net.Data tables on the function definition, and the SQL statement returns result sets, the SQL language environment stores each result set in the specified tables. You can then use the table later in the macro. If an OUT table is not specified, the SQL language environment uses a default table.
Nested SQL Statements
You can call other SQL functions from within a ROW block of another SQL function. Use unique Net.Data table names in each of the SQL functions, otherwise, unpredictable results might occur.
Example: Calls an SQL function from the ROW block of another SQL function
%define mytable1 = %TABLE %define mytable2 = %TABLE %FUNCTION(DTW_SQL) sql2 (IN p1, OUT t2) { select * from NETDATA.STAFFINF where projno='$(p1)' %REPORT { %ROW { $(N1) is $(V1) %} %} %} %FUNCTION(DTW_SQL) sql1 (OUT t1) { select * from NETDATA.STAFFINF %REPORT { %ROW { @sql2(V1, mytable2) %} %} %} %HTML(netcall1) { @sql1(mytable1) %}
The SQL language environment supports variables designed to support DB2. For example, the DATABASE variable specifies the data source that the SQL language environment connects to when executing an SQL statement. The following list specifies which variables are supported for the SQL language environment. See Net.Data Reference for description, syntax, and examples for these variables.
The SQL language environment supports the data types listed in Table 5
BLOB(1) | DOUBLE | SMALLINT |
CHAR | DOUBLEPRECISION | TIME |
CLOB(1) | FLOAT | TIMESTAMP |
DATE | GRAPHIC | VARCHAR |
DBCLOB(1) | INTEGER | VARGRAPHIC |
DECIMAL | REAL |
|
(1) These data types cannot be passed as parameters to a stored procedure call. To learn which data types are support for stored procedures, see Stored Procedure Syntax
See Data Type Considerations to learn about special considerations for the LOBs and DATALINK data types.
Consider the following restrictions when planning your environment:
See Managing Multiple Database Connections for more information about these restrictions.