今天oracle群上有人問mysql可不可以執行動態的sql語句,搜了一下,居然可以。
set @tsql='select * from companyinfo';
prepare stmt1 from @tsql;
execute stmt1;
set @fid='fid';
set @table1='companyinfo';
set @tsql=concat('select ',@fid,' from ',@table1);
prepare stmt1 from @tsql;
execute stmt1;
mysql> use test
database changed
mysql> set @fid='fid';
query ok, 0 rows affected (0.00 sec)
mysql> set @table1='companyinfo';
query ok, 0 rows affected (0.00 sec)
mysql> set @tsql=concat('select ',@fid,' from ',@table1);
query ok, 0 rows affected (0.00 sec)
mysql> prepare stmt1 from @tsql;
query ok, 0 rows affected (0.00 sec)
statement prepared
mysql> execute stmt1;
+------+
| fid |
+------+
| 1001 |
+------+
1 row in set (0.00 sec)
mysql> use test
database changed
mysql> set @tsql='select titleof into @ename from employeelist where eid=2';
query ok, 0 rows affected (0.00 sec)
mysql> prepare stmt1 from @tsql;
query ok, 0 rows affected (0.00 sec)
statement prepared
mysql> execute stmt1;
query ok, 1 row affected (0.00 sec)
mysql> select @ename;
+-----------+
| @ename |
+-----------+
| 榪炶姵鑺? |
+-----------+
1 row in set (0.00 sec)
mysql>
MySQL 儲存過程中執行動態 SQL 語句
mysql 02mysql delimiter 03mysql 04mysql createprocedureset col value 05 in tablevarchar 128 06 in columnvarchar 128 07 in new valuevarchar 1000 08 in ...
PL SQL執行動態SQL(二)
pl sql動態sql 依據 dbms sql包 這個包提供了一種使用動態sql來訪問資料庫的方法。示例 1.執行插入刪除等dml語句 declare v cursorid number v insertrecords varchar2 500 v numrows integer begin v c...
JDBC中執行靜態SQL和執行動態SQL區別
1.執行靜態sql 獲取到的statement執行sql語句物件 只能執行靜態的sql語句 sql寫死 直接執行的 拼接sql 載入驅動 獲取連線物件 獲取執行語句物件 執行sql語句 a.executequery sql 查 a.executeupdate sql 增刪改 處理結果集物件 釋放資源...