Advanced Server also supports dynamic queries via the OPEN FOR USING statement. A string literal or string variable is supplied in the OPEN FOR USING statement to the SELECT command.
name is the identifier of a previously declared cursor variable. dynamic_string is a string literal or string variable containing a SELECT command (without the terminating semi-colon). bind_arg, bind_arg_2... are bind arguments that are used to pass variables to corresponding placeholders in the SELECT command when the cursor variable is opened. The placeholders are identifiers prefixed by a colon character.
The following is an example of a dynamic query using a string literal.
The following is the output when the procedure is executed.
In the next example, the previous query is modified to use bind arguments to pass the query parameters.
The following is the resulting output.
Finally, a string variable is used to pass the SELECT providing the most flexibility.