title: In MySQL: How to pass a table name as stored procedure and/or function argument?
body: <p>For instance, this does not work:</p>
  
  <pre><code>DELIMITER //
  CREATE PROCEDURE countRows(tbl_name VARCHAR(40))
    BEGIN
      SELECT COUNT(*) as ct FROM tbl_name;
    END //
  
  DELIMITER ;
  CALL countRows('my_table_name');
  </code></pre>
  
  <p>Produces:</p>
  
  <pre><code>ERROR 1146 (42S02): Table 'test.tbl_name' doesn't exist
  </code></pre>
  
  <p>However, this works as expected:</p>
  
  <pre><code>SELECT COUNT(*) as ct FROM my_table_name;
  </code></pre>
  
  <p>What syntax is required to use an argument as a table name in a select statement? Is this even possible?</p>