©SQL :: Manager
HomeProgram InformationTechnical detailsFree downloadDonate for a cup of coffee
myway SQL Manager for MySQL and MariaDB, Download on Uptodown
SQL functionMySQLMariaDB

The NAME_CONST SQL Function in MySQL and MariaDB - Name constant for column

NAME_CONSTSyntax:NAME_CONST(Name, Value)
Return value:Depending on the data types used
Function type:Miscellaneous function
Function Description

The NAME_CONST() function returns the specified "Value" under the specified label "Name".

When NAME_CONST() is used to create a result set column, it causes the column to have the specified name.

The arguments should be constants, exceptions for "Value" seem to be functions that themselves return constant values ​​like PI() or VERSION().


The NAME_CONST() function is used internally when replicating stored procedures. There is little point in using them in SQL statements. Value naming works more flexibly with the AS clause.

SQL Examples for the NAME_CONST function

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11

SELECT name_const('my_name', 100);
SELECT name_const('my_txt''Text');
sELECT name_const('my_pi'pi());
sELECT name_const('my_ver'version());
SELECT name_const('my_time'now());

SELECT name_const('my_null'null);
SELECT name_const(14, 'Test');
SELECT name_const(14.1, 'Test');

my_name
int(3)
100
my_txt
varchar(4) BINARY
Text
my_pi
double(8)
3.141593
my_ver
varchar(32) BINARY
10.5.13-MariaDB-0ubuntu0.21.04.1
  select NAME_CONST('my_time'now()) 
errno: 1210  sqlstate: HY000  error: Incorrect arguments to NAME_CONST  
my_null
NULL
14
varchar(4) BINARY
Test
14.1
varchar(4) BINARY
Test
The examples were created with the MyWAY SQL manager: Download

How to use the NAME_CONST() function in MySQL and MariaDB databases

In MySQL and MariaDB the NAME_CONST() function is used to create a named constant within a SQL statement and assign a specific value to this constant, which can be referenced multiple times within the SQL statement and thus be made available for calculations or expressions within the statement. This allows the value to be used multiple times in complex queries. By assigning values ​​to named constants, SQL statements can be made more readable and maintainable. Instead of using hard-coded values ​​multiple times in queries, constants can be referenced, which are easier to change when needed.

The NAME_CONST() function is evaluated during query execution and the named constants are only specific to the current SQL statement. They are not accessible outside of the interrogation area.
MODMONTHMONTHNAMENAME_CONSTNEXTVALNOWNULLIF

Further MySQL und MariaDB SQL Miscellaneous functions

BIN_TO_UUIDBIN_TO_UUID(Binary string [, Swap])
More about BIN_TO_UUID Function

GET_LOCKGET_LOCK()

INET6_ATONINET6_ATON(String)
More about INET6_ATON Function

INET6_NTOAINET6_NTOA(Binary string)
More about INET6_NTOA Function

INET_ATONINET_ATON(String)
More about INET_ATON Function

INET_NTOAINET_NTOA(Value)
More about INET_NTOA Function

IS_FREE_LOCKIS_FREE_LOCK()

IS_IPV4IS_IPV4(String)
More about IS_IPV4 Function

IS_IPV4_COMPATIS_IPV4_COMPAT(String)

IS_IPV4_MAPPEDIS_IPV4_MAPPED(String)

IS_IPV6IS_IPV6(String)
More about IS_IPV6 Function

IS_USED_LOCKIS_USED_LOCK()

IS_UUIDIS_UUID(String)
More about IS_UUID Function

MASTER_GTID_WAITMASTER_GTID_WAIT()

MASTER_POS_WAITMASTER_POS_WAIT()

RELEASE_ALL_LOCKSRELEASE_ALL_LOCKS()

RELEASE_LOCKRELEASE_LOCK()

SYS_GUIDSYS_GUID()
More about SYS_GUID Function

UUIDUUID()
More about UUID Function

UUID_SHORTUUID_SHORT()
More about UUID_SHORT Function

UUID_TO_BINUUID_TO_BIN(String [, Swap])
More about UUID_TO_BIN Function

Numeric functionsString functionsRegular ExpressionsDate and Time functions
Comparison functionsEncryption & CompressionConversion functionsNULL functions
Aggregate functionsWindow functionsJSON functionsGeometric functions
Sequence functionsInformation functionsDynamic ColumnsMiscellaneous functions
More information about the NAME_CONST SQL function: mysql.com and mariadb.com
Updated: 2023-09-17ImprintContactTerms & conditionsPrivacy & CookiesUpdatesSitemapFacebookLinkedinTwitterStatistics©2020-2024 Heino Cunze-Fischer