可以使用哪种SQL语句来准备语句?
实际上,不可能准备所有SQL语句,因为MySQL仅允许以下类型的SQL语句可以准备:
SELECT陈述式
示例
mysql> PREPARE stmt FROM 'SELECT tender_value from Tender WHERECompanyname = ?';
Statement prepared
mysql> SET @A = 'Singla Group.';
mysql> EXECUTE stmt using @A;
+--------------+
| tender_value |
+--------------+
| 220.255997 |
+--------------+
1 row in set (0.07 sec)
mysql> DEALLOCATE PREPARE stmt;
插入,替换,更新和删除
修改数据的语句。
示例
mysql> PREPARE stmt1 FROM 'DELETE from Tender WHERE Sr = ?';Statement prepared
mysql> SET @A = 4;
mysql> EXECUTE stmt1;
ERROR 1210 (HY000): Unknown error 1210
mysql> EXECUTE stmt1 using @A;
mysql> DEALLOCATE PREPARE stmt1;
mysql> Select * from tender;
+----+---------------+--------------+
| Sr | CompanyName | Tender_value |
+----+---------------+--------------+
| 1 | Abc Corp. | 250.369003 |
| 2 | Khaitan Corp. | 265.588989 |
| 3 | Singla group. | 220.255997 |
+----+---------------+--------------+
3 rows in set (0.00 sec)
CREATE TABLE语句。
示例
mysql> PREPARE stmt3 FROM 'CREATE TABLE Student(Id INT, NameVarchar(20))';
Statement prepared
mysql> EXECUTE stmt3;
mysql> DEALLOCATE PREPARE stmt3;
SET,DO和许多SHOW语句
示例
mysql> PREPARE stmt10 FROM 'SHOW TABLES';Statement prepared
mysql> EXECUTE stmt10;
+-------------------+
| Tables_in_query |
+-------------------+
| emp |
| emp123 |
| emp_t |
| examination_btech |
| new_number |
| student |
| student_detail |
| student_info |
| tender |
| website |
+-------------------+
10 rows in set (0.00 sec)
以上是 可以使用哪种SQL语句来准备语句? 的全部内容, 来源链接: utcz.com/z/322060.html