LEN

LEN is an SQL function that returns the length of a string in terms of number of characters.

LEN(string);

  • string: The input string of which the length is to be determined. The LEN() function will return the number of characters in the string.

Example

SELECT LEN('Hello World');

Output

11

Explanation

The LEN function is used to get the length of a string in SQL. In the given example, the string is ‘Hello World’ which has a length of 11.

LEN( string_expression )

  • string_expression: The string expression can be any type of character string for which the length is to be returned. The STRING_EXPRESSION is an expression, typically a column that will be evaluated to a text string. The LEN function then counts the number of characters in that text string.

Example

SELECT LEN('Hello, World!');

Output

12

Explanation

In the example, the LEN() function is used to calculate the length of the string ‘Hello, World!’, which is 12. This count does not include trailing spaces.

LEN(string)

  • string: Represents the input string for which the length is calculated. This character input can be of data type CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB. The length returned is the number of characters in the string. For any NULL input, the return value is NULL.

Example

SELECT LEN('Hello World') AS LengthOfString FROM dual;

Output

10

Explanation

The LEN function in this query returns the length of the string ‘Hello World’, which is 10 characters.

For in-depth explanations and examples SQL keywords where you write your SQL, install our extension.