Table of Contents
EXECUTE
Syntax
EXECUTE statement [USING parameter [,...] ]
Arguments
statement
The string variable or literal that should be executed.
parameter
The name of a variable to be passed into a routine as a binding parameter for the statement.
Description
The EXECUTE statement allows to treat the passed string as a query and run it.
Important to note that Valentina engine does not require you to PREPARE/DROP statements as do some other DBMS.
Examples
Example
CREATE PROCEDURE sp1( IN param Long ) BEGIN -- Prepare text of the query SET @a = ( 'SELECT f1, f2 FROM t1 WHERE f1 = ' || param ); -- Execute the query (The cursor will be returned). EXECUTE @a; END;
Example
The same example but argument is used for binding instead of implicated it in the query text.
CREATE PROCEDURE sp1( IN param Long ) BEGIN -- Prepare text of the query SET @a = 'SELECT f1, f2 FROM t1 WHERE f1 = :1'; -- Execute the query (The cursor will be returned). EXECUTE @a USING param; END;
Example
CREATE PROCEDURE sp1 ( IN inTblName String ) BEGIN SET @query = 'SELECT last_recid_of_table( ' || inTblName || ') INTO @lastRecID'; EXECUTE @query; -- now session variable @lastRecID contains last REC IF of the specified table END