LENGTH
LENGTH is a function in SQL that is used to obtain the number of characters in a specific string.
LENGTH(str)
- str: The string argument for which the length is to be returned. The function LENGTH(str) returns the length of the string str in bytes.
Example
Output
Explanation
The LENGTH function in MySQL is used to retrieve the length of a string. In this example, it is applied to the string ‘SQL Documentation’, returning 17, which represents the number of characters (including spaces) in this string.
LENGTH(string text) RETURNS integer
- string text: This is the text string that you want to measure the length of. It is made up of any sequence of characters.
- returns integer: This indicates the type of output returned by the LENGTH function. It returns the integer value representing the number of characters in the specified string text.
Example
Output
Explanation
The LENGTH
function returns the number of characters in the string ‘PostgreSQL’, which is 11.
LENGTH( string )
- string: This refers to the string for which length is to be calculated. LENGTH function returns the number of characters in the string.
Example
Output
Explanation
The LENGTH function in SQL Server returns the number of characters in the provided string. In the given example, the string ‘SQL Server’ consists of 11 characters, including the space, so the output is 11.
LENGTH(string)
- string: This is the input parameter to the LENGTH function. The string parameter is the character string from which LENGTH function will count the number of characters. If the input string is of CHAR data type, it trims trailing blanks. For null input, the LENGTH function returns null.
Example
Output
Explanation
The LENGTH function in Oracle SQL returns the length of the provided string, in this case ‘Hello, World!’, which is 13. The LENGTH function counts the number of characters in the input string, including punctuation and spaces.
LENGTH(X)
- x: The string value whose length is to be determined. LENGTH(X) function returns the length of the string X.
Example
Output
Explanation
The LENGTH
function in SQLite is used to determine the length of a specified string. In this case, the string ‘SQL Documentation’ has a length of 16. The space between the words is included in this count.