mysql 動態執行SQL文

2021-04-22 02:50:40 字數 769 閱讀 7096

在mysql儲存過程中動態執行sql文

mysql>prepare stmt1 from 'select sqrt(pow(?,2) + pow(?,2)) as hypotenuse';

mysql>set @a = 3;

mysql>set @b = 4;

mysql>execute stmt1 using @a, @b;

mysql>set @a = 'select * from table1 ';

mysql>set @b = 'where column1>10 limit 1';

mysql>set @a =concat(@a,@b);

mysql>prepare stmt1 from@a;

mysql>execute stmt1;

參考:http://dev.mysql.com/doc/refman/5.0/en/sql-syntax-prepared-statements.html

mysql 動態執行SQL文

參考 mysql 儲存過程中動態執行 sql 文 2 pow mysql prepa re stmt1 from select sqrt pow 2 as hypotenuse mysql set a 3 mysql set b 4 b class userinputexecute stmt1 us...

mysql 過程 動態執行sql

begin declare v sql varchar 500 declare v table name varchar 20 declare v date time varchar 20 set v date time date format now y m d select v date tim...

mysql執行動態sql語句

今天oracle群上有人問mysql可不可以執行動態的sql語句,搜了一下,居然可以。set tsql select from companyinfo prepare stmt1 from tsql execute stmt1 set fid fid set table1 companyinfo s...