可以通过以下示例来理解,其中使用准备好的语句创建了名为“ Student”的表-
mysql> PREPARE stmt3 FROM 'CREATE TABLE Student(Id INT, Name Varchar(20))'; Statement prepared mysql> EXECUTE stmt3; mysql> DEALLOCATE PREPARE stmt3;
现在,在使用准备好的语句进行以下查询的帮助下,我们可以插入值
在表'学生'中-
mysql> PREPARE stmt7 FROM 'INSERT INTO Student(Id,Name) values(?,?)'; Statement prepared mysql> SET @A = 1, @B = 'Ram'; mysql> EXECUTE stmt7 using @A, @B; mysql> SET @A = 2, @B = 'Shyam'; mysql> EXECUTE stmt7 using @A, @B; mysql> SET @A = 3, @B = 'Mohan'; mysql> Select * from Student; +------+-------+ | Id | Name | +------+-------+ | 1 | Ram | | 2 | Shyam | | 3 | Mohan | +------+-------+ 3 rows in set (0.00 sec)