title: Using a variable as a column name in a stored procedure?
body: <p>Here I wrote a mysql procedure which select all <code>text</code> type field of specified database 'wp'</p>
  
  <p>and I want to <strong>update</strong> every <strong>text</strong> type field row appending <strong>extra string</strong> via <strong>CONCAT</strong> function.</p>
  
  <p>after I <strong>call test2</strong> , error shows:</p>
  
  <pre><code>Query : call test2()
  
  Error Code : 1146
  Table 'wp._tbl' doesn't exist
  
  Execution Time : 00:00:00:000
  Transfer Time  : 00:00:00:000
  Total Time     : 00:00:00:000
  ---------------------------------------------------
  </code></pre>
  
  <p>mysql regards <strong>_tbl</strong> as a string but not a variable.</p>
  
  <p>So can I correct this?</p>
  
  <p>code:   </p>
  
  <pre><code>DELIMITER $$
  USE `wp`$$
  DROP PROCEDURE IF EXISTS `test2`$$
  CREATE
      PROCEDURE `test2`()
      BEGIN
      DECLARE _tbl VARCHAR(100);
      DECLARE _cl VARCHAR(100);
      DECLARE notFound INT DEFAULT 0;
      DECLARE cur CURSOR FOR SELECT table_name,column_name FROM information_schema.columns WHERE table_schema = 'wp' AND data_type ='text';
      DECLARE CONTINUE HANDLER FOR NOT FOUND SET notFound =1;
      OPEN cur;
          WHILE notFound = 0 DO
              FETCH cur INTO _tbl,_cl;
              UPDATE _tbl SET _cl = CONCAT(_cl,'extra string goes here.....');
              IF NOT noFound THEN SET notFound = 0;
              END IF;
          END WHILE;
      CLOSE cur;
      END$$
  
  DELIMITER ;
  </code></pre>