Collections:
STATEMENT_DIGEST_TEXT() - Calculating Statement Digest
How to calculate MySQL statement digest using the STATEMENT_DIGEST_TEXT() function?
✍: FYIcenter.com
STATEMENT_DIGEST_TEXT(statement) is a MySQL built-in function that
normalizes a given MySQL statement into a statement digest.
For example:
SELECT STATEMENT_DIGEST_TEXT('SELECT NOW()');
-- +---------------------------------------+
-- | STATEMENT_DIGEST_TEXT('SELECT NOW()') |
-- +---------------------------------------+
-- | SELECT NOW ( ) |
-- +---------------------------------------+
SELECT STATEMENT_DIGEST_TEXT('SELECT help_topic_id, name FROM mysql.help_topic');
-- +---------------------------------------------------------------------------+
-- | STATEMENT_DIGEST_TEXT('SELECT help_topic_id, name FROM mysql.help_topic') |
-- +---------------------------------------------------------------------------+
-- | SELECT `help_topic_id` , NAME FROM `mysql` . `help_topic` |
-- +---------------------------------------------------------------------------+
Note that multiple MySQL statements may have the same statement digest. For example:
SET @stmt = 'SELECT * FROM mytable WHERE cola = 10 AND colb = 20'; SELECT STATEMENT_DIGEST_TEXT(@stmt); -- +---------------------------------------------------------+ -- | STATEMENT_DIGEST_TEXT(@stmt) | -- +---------------------------------------------------------+ -- | SELECT * FROM `mytable` WHERE `cola` = ? AND `colb` = ? | -- +---------------------------------------------------------+ SET @stmt = 'SELECT * FROM mytable WHERE cola = 1 AND colb = 2'; SELECT STATEMENT_DIGEST_TEXT(@stmt); -- +---------------------------------------------------------+ -- | STATEMENT_DIGEST_TEXT(@stmt) | -- +---------------------------------------------------------+ -- | SELECT * FROM `mytable` WHERE `cola` = ? AND `colb` = ? | -- +---------------------------------------------------------+
Also note that STATEMENT_DIGEST_TEXT() validates the given MySQL statement before calculating the hash value. If an invalid statement is provided, you will get an error. For example:
SELECT STATEMENT_DIGEST_TEXT('I AM NOT A STATEMENT');
ERROR 3676 (HY000): Could not parse argument to digest function:
"You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near
'I AM NOT A STATEMENT' at line 1".
Reference information of the STATEMENT_DIGEST_TEXT() function:
STATEMENT_DIGEST_TEXT(statement): str Normalizes a given MySQL statement into a statement digest. Arguments, return value and availability: statement: Required. The MySQL statement string to be processed. str: Return value. The statement digest. Available since MySQL 4.1.
Related MySQL functions:
⇒ UNCOMPRESS() - Uncompressing Data
⇐ STATEMENT_DIGEST() - Statement Digest Hash
2023-12-15, 1399🔥, 0💬
Popular Posts:
How AdventureWorksLT tables are related in SQL Server? There are 12 user tables defined in Adventure...
How To Change the Password for Your Own User Account in MySQL? If you want to change the password of...
What is dba.FYIcenter.com Website about? dba.FYIcenter.com is a Website for DBAs (database administr...
How To Convert Numeric Values to Character Strings in MySQL? You can convert numeric values to chara...
How to change the data type of an existing column with "ALTER TABLE" statements in SQL Server? Somet...