熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> SQL Server >> 正文

用MySQL實現SQL Server的Sp

2022-06-13   來源: SQL Server 

  從MySQL 開始支持了一個全新的SQL句法

  PREPARE stmt_name FROM preparable_stmt;
  EXECUTE stmt_name [USING @var_name [ @var_name] ];
  {DEALLOCATE | DROP} PREPARE stmt_name;

  通過它我們就可以實現類似 MS SQL 的 sp_executesql 執行動態SQL語句!

  同時也可以防止注入式攻擊!

  為了有一個感性的認識下面先給幾個小例子

  mysql> PREPARE stmt FROM SELECT SQRT(POW(?) + POW(?)) AS hypotenuse;
  mysql> SET @a = ;
  mysql> SET @b = ;
  mysql> EXECUTE stmt USING @a @b;
  ++
  | hypotenuse |
  ++
  | |
  ++
  mysql> DEALLOCATE PREPARE stmt;
  mysql> SET @s = SELECT SQRT(POW(?) + POW(?)) AS hypotenuse;
  mysql> PREPARE stmt FROM @s;
  mysql> SET @a = ;
  mysql> SET @b = ;
  mysql> EXECUTE stmt USING @a @b;
  ++
  | hypotenuse |
  ++
  | |
  ++
  mysql> DEALLOCATE PREPARE stmt;

[]  []  []  


From:http://tw.wingwit.com/Article/program/SQLServer/201311/22371.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.