Programming Guide |
Executes the SQL statement declared for a named cursor
DBMS [WITH CURSORcursor
] EXECUTE [USINGargs
]
WITH CURSOR
cursor
- Name of declared
SELECT
cursor. If the clause is not used, Panther uses the defaultSELECT
cursor.args
- Panther variables containing parameter values.
Use
DBMS EXECUTE
to execute the statement associated with a declared cursor.
DBMS EXECUTE
does not support theWITH CONNECTION
clause. Panther uses the connection that was specified either by name or by default when the cursor was declared. The only way to change the cursor's engine or connection is to redeclare the cursor.If an application is executing a similar statement many times, it is often more efficient to declare a cursor for the statement. Usually the database engine saves the parsed statement, executing it when the application executes the cursor. It is not necessary to redeclare the cursor to supply new data for a
WHERE
orVALUES
clause. Instead, the application can declare the cursor and use a substitution parameter for each value that the application supplies when it executes the cursor. Substitution parameters begin with a double colon (::
). For example:DBMS DECLARE c1 CURSOR FOR \
SELECT * FROM titles WHERE name LIKE ::name_parm
name_parm
is a place holder for the value that will be supplied when the cursor is executed. For example:DBMS WITH CURSOR c1 EXECUTE USING "St%"This command fetches rows where name begins with the characters
"St"
. The application could execute the cursor repeatedly, each time with a new value. It can use the value of a field to supply a value. For example:DBMS WITH CURSOR c1 EXECUTE USING anameSince
aname
is not quoted, Panther assumes it is a Panther variable. If an argument in theUSING
clause is a widget or LDB variable that has date/time, currency, null field, or type property specifications, Panther formats the variable's value before passing it to the database engine. Refer to Chapter 30, "Writing Information to the Database," in Application Development Guide for details of this topic.
DBMS DECLARE x CURSOR FOR \
SELECT * FROM tapes WHERE title_id=::p1 AND copy_num=::p2// bind by position:DBMS WITH CURSOR x EXECUTE USING code, copy_id// or bind by name:DBMS WITH CURSOR x EXECUTE \
USING p1 = code, p2 = copy_id
DECLARE CURSOR
,CLOSE CURSOR
,WITH CURSOR