SQL Programming Manual for TAL
NonStop SQL Statements and Directives
HP NonStop SQL Programming Manual for TAL—527887-001
3-35
SQL
When to Initialize a Cursor. Opening a cursor causes the set of rows in the query
result to be defined and ordered. If a cursor SELECT statement contains host variables
in its WHERE clause, you must initialize the values of the host variables either before
you open the cursor with an OPEN statement or else in the USING clause of the
OPEN statement.
The SQL executor places the input variables into its buffers when it opens the cursor. If
you do not initialize the variables before the OPEN statement, several things can
happen:
•
If the variables contain values that do not conform to the data type expected,
overflow or truncation errors can result when the cursor is opened.
•
If the variables are of the expected type but they contain values left from a previous
usage of the program, these bad values are used as a starting point for
subsequent FETCH operations. As a result, the returned rows do not begin at the
expected location.
When to Close a Cursor. Only an explicit CLOSE statement or a FREE RESOURCES
statement closes an open cursor. As a general rule, you can leave cursors open to
save the overhead of reopening a cursor you plan to use again. In some cases,
however, you should explicitly close open cursors. In particular, when you use cursors
in PATHWAY applications, you should follow these rules:
1. Close any open cursors before returning control to a requester.
2. If your program is a server and a TMF transaction was started in a requester, close
any cursors to release space used by the cursors and to free locks before returning
control to the requester.
SQL
The SQL TAL compiler directive causes the TAL compiler to process subsequent SQL
statements and directives. Put the SQL directive in the first line of the primary source
file or in the command line when you run the TAL compiler.
SQL [ option ]
[ ( option [ , option ] ... ) ]
option is:
[ PAGES num-pages ]
[ WHENEVERLIST | NOWHENEVERLIST ]
[ RELEASE1 | RELEASE2 ]
[ SQLMAP | NOSQLMAP ]