The miscellaneous built-in functions described in the following sections perform operations that do not fall into the categories described in earlier sections.
BENCHMARK executes the
specified expression repeatedly. It is intended to be used to
benchmark MySQL performance. This function has very little
applicability in a stored program context, although in theory you
could use it to repeatedly execute a stored program.
COALESCE returns the first
non-NULL value in the provided list of values.
SET var1=1; → 1 SET var2=2; → 2 SET var3=NULL; → SET var4=COALESCE(var1,var2,var3); → 1 SET var5=COALESCE(var3,var2,var1) ; → 2
CURRENT_USER returns the
username and hostname of the current MySQL user. It may report a
different value from that returned by
USER, since the
USER function reports the connection
requested by the user, rather than the connection that was actually
SET var1=CURRENT_USER( ); → root@% SET var2=USER( ); → email@example.com
DATABASE returns the name
of the database currently in use.
USE prod; SET var1=database( ); → prod
GET_LOCK allows you to
define and acquire a user-defined lock. The
lock_name can be a string of your choice.
GET_LOCK will attempt to acquire the lock; then, if no other session holds the lock, it will return ...