How To have Dynamic SQL in MySQL Stored Procedure

前端 未结 3 1800
无人共我
无人共我 2020-11-21 22:10

How do you build and use dynamic sql in a MySQL stored procedure?

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-21 23:03

    You can pass thru outside the dynamic statement using User-Defined Variables

    Server version: 5.6.25-log MySQL Community Server (GPL)
    
    mysql> PREPARE stmt FROM 'select "AAAA" into @a';
    Query OK, 0 rows affected (0.01 sec)
    Statement prepared
    
    mysql> EXECUTE stmt;
    Query OK, 1 row affected (0.01 sec)
    
    DEALLOCATE prepare stmt;
    Query OK, 0 rows affected (0.01 sec)
    
    mysql> select @a;
    +------+
    | @a   |
    +------+
    |AAAA  |
    +------+
    1 row in set (0.01 sec)
    

提交回复
热议问题