Prepare Statements

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;

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.