Prepare Statements
Prepare Statements
prepare statements used for creating dynamic queries.
Using following SQL statements,we can create a prepare statement .
PREPARE:
Used for create a prepare a statement with query.
Syntax:
PREPARE stmt_name FROM ‘query’;
example:
PREPARE st1 FROM ‘SELECT name from table1 where emp_id=? ‘;
EXECUTE:
By this statement, we execute the query by passing all required values.
Syntax:
EXECUTE stmt_name USING val1,val2, . . .:
Example:
SET @id=1;
EXECUTE st1 USING @id;
Here ,
id value assigned to emp_id in query and execute query.
DEALLOCATE or DROP:
Used to deallocate a prepared statement.
Syntax:
DEALLOCATE PREPARE stmt_name
Example:
DEALLOCATE PREPARE st1;
