Mysql stored procedure don't take table name as parameter

后端 未结 4 1753
不思量自难忘°
不思量自难忘° 2020-12-03 16:47

I\'ve written a stored procedure. It\'s working fine except taking the table name as input parameter.

Let see my proc in MySQL:

DELIMITER $$
USE `d         


        
4条回答
  •  再見小時候
    2020-12-03 17:03

    Although may not be what you want, alternatively, can consider to use conditionally if and prepare the statement.

    DELIMITER $$
    CREATE PROCEDURE select_count(IN table_name VARCHAR(20))
    BEGIN
      IF table_name = 'xxx' THEN
         SELECT * FROM xxx;
      ELSEIF table_name = 'yyy' THEN
         ...
      ENDIF
    END$$
    

提交回复
热议问题