Switch to: V9V8V7V6V5

EXECUTE

Syntax

EXECUTE statement [USING parameter [,...] ]

Arguments

statement

The string variable or literal that should be executed.

parameter

The name of variable to be passed into 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 do not require from you 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 using 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 specified table
END