Home > Database > Mysql Tutorial > body text

MySQL 存储过程中执行动态 SQL 语句

WBOY
Release: 2016-06-07 14:54:30
Original
1196 people have browsed it

无详细内容 MySQL mysqlmysql delimiter $$mysqlmysql CREATE PROCEDURE set_col_value - (in_table VARCHAR(128), - in_column VARCHAR(128), - in_new_value VARCHAR(1000), - in_where VARCHAR(4000)) - - BEGIN - DECLARE l_sql VARCHAR(4000); - SET l_s

MySQL
mysql>
mysql> delimiter $$
mysql>
mysql> CREATE PROCEDURE set_col_value
    ->        (in_table     VARCHAR(128),
    ->         in_column    VARCHAR(128),
    ->         in_new_value VARCHAR(1000),
    ->         in_where     VARCHAR(4000))
    ->
    -> BEGIN
    ->    DECLARE l_sql VARCHAR(4000);
    ->    SET l_sql=CONCAT_ws(' ',
    ->                'UPDATE',in_table,
    ->                   'SET',in_column,'=',in_new_value,
    ->                ' WHERE',in_where);
    ->    SET @sql=l_sql;
    ->    PREPARE s1 FROM @sql;
    ->    EXECUTE s1;
    ->    DEALLOCATE PREPARE s1;
    -> END$$
Query OK, 0 rows affected (0.00 sec)
Copy after login
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template