cool hit counter MySQL Using Comments as Table Headers_Intefrankly

MySQL Using Comments as Table Headers


Use the Chinese comment as the header of the query result

Effectiveness demonstration

 # Delete if procedure exists
DROP PROCEDURE IF EXISTS sel;
 # Create a stored procedure
CREATE PROCEDURE sel(db VARCHAR(21845), tab VARCHAR(21845))
   # Start content
  BEGIN
     # Generate statements to put @colas comments on query columns
    SET @s = concat('
      SELECT group_concat(CASE COLUMN_COMMENT
                          WHEN '' THEN COLUMN_NAME
                          ELSE concat(COLUMN_NAME, ' AS ', COLUMN_COMMENT)
                          END SEPARATOR ', ') AS colas
      INTO @colas FROM information_schema.COLUMNS
      WHERE TABLE_SCHEMA = '', db, '' AND TABLE_NAME = '', tab, ''
    ');

     # Pre-compilation, execution, release
    PREPARE sel FROM @s;
    EXECUTE sel;
    DEALLOCATE PREPARE sel;

     # Splice simple query statements
    SET @s = concat('SELECT ', @colas, ' FROM ', db, '.', tab);

    PREPARE sel FROM @s;
    EXECUTE sel;
  END;

 # Query saved column names AS Comments,
SELECT @colas;

# Examples of use sel(' databases', ' a table (listing information)');
CALL sel('test', 'job_depend');

 # Pre-compiled statements are then executed
EXECUTE sel;

Recommended>>
1、Silverlight 20 beta1 stack
2、leetcode10RegularExpressionMatching
3、SpringMVC working principle and annotation description
4、You may need to adapt iOS 11 for your app
5、Two or three potholes and solutions for the long press QR code recognition feature in WeChats builtin browser

    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号