什么样的SQL语句可以用来准备语句?

WBOY
发布: 2023-09-04 17:41:02
转载
732 人浏览过

什么样的SQL语句可以用来准备语句?

实际上,不可能准备所有的 SQL 语句,因为 MySQL 只允许准备以下几种 SQL 语句:

SELECT 语句

示例

mysql> PREPARE stmt FROM 'SELECT tender_value from Tender WHERE
Companyname = ?';
Query OK, 0 rows affected (0.09 sec)
Statement prepared

mysql> SET @A = 'Singla Group.';
Query OK, 0 rows affected (0.00 sec)

mysql> EXECUTE stmt using @A;
+--------------+
| tender_value |
+--------------+
|   220.255997 |
+--------------+
1 row in set (0.07 sec)

mysql> DEALLOCATE PREPARE stmt;
Query OK, 0 rows affected (0.00 sec)
登录后复制

INSERT, REPLACE, UPDATE和DELETE

修改数据的语句。

示例

mysql> PREPARE stmt1 FROM 'DELETE from Tender WHERE Sr = ?';
Query OK, 0 rows affected (0.00 sec)
Statement prepared

mysql> SET @A = 4;
Query OK, 0 rows affected (0.00 sec)

mysql> EXECUTE stmt1;
ERROR 1210 (HY000): Unknown error 1210

mysql> EXECUTE stmt1 using @A;
Query OK, 1 row affected (0.08 sec)

mysql> DEALLOCATE PREPARE stmt1;
Query OK, 0 rows affected (0.00 sec)

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, Name
Varchar(20))';
Query OK, 0 rows affected (0.00 sec)
Statement prepared

mysql> EXECUTE stmt3;
Query OK, 0 rows affected (0.73 sec)

mysql> DEALLOCATE PREPARE stmt3;
Query OK, 0 rows affected (0.00 sec)
登录后复制

SET、DO 和许多 SHOW 语句

示例

mysql> PREPARE stmt10 FROM 'SHOW TABLES';
Query OK, 0 rows affected (0.00 sec)
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语句可以用来准备语句?的详细内容。更多信息请关注PHP中文网其他相关文章!

来源:tutorialspoint.com
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板