title: MySQL : How to dynamically call stored procedures when inserting new row in table
body: <p>I have a query that dynamically convert rows into column when inserting new row in table. However, every time I inserting new row in table I need to call the stored procedure to show the output <code>call bian_test_db.new_procedure();</code>. How can I make it automatically show the new insert data in view without calling the procedure.</p>
  
  <pre><code>CREATE DEFINER=`root`@`localhost` PROCEDURE `new_procedure`()
  BEGIN
  SET SESSION group_concat_max_len = 1000000;
  SELECT
    GROUP_CONCAT(DISTINCT
      CONCAT(
        'ifnull(SUM(case when itemname = ''',
        itemname,
        ''' then itemvalue end),0) AS ',
        itemname
      )
    ) INTO @sql
  FROM
    bian_test_db.history;
  SET @sql = CONCAT('CREATE OR REPLACE view testing as SELECT user_id, ', @sql, ' 
                    FROM bian_test_db.history 
                     GROUP BY user_id');
  
  PREPARE stmt FROM @sql;
  EXECUTE stmt;
  DEALLOCATE PREPARE stmt;
  
  END
  </code></pre>