Oracle PL/SQL LENGTH Function

Oracle PLSQL Length FunctionOracle PL/SQL LENGTH Function is used to return the length of a string. Oracle LENGTH Function calculates length by considering characters of input.


Oracle PL/SQL LENGTH Function Sytntax

SELECT LENGTH(string)
FROM table_name;

“string” is the string whose length is to be determined, if the length of the string is NULL then LENGTH Function returns NULL.


Oracle PL/SQL LENGTH Function – Use with SELECT Statement Example

The Oracle LENGTH Function is used with the SQL SELECT Statement.

For example the SQL SELECT Statement query with LENGTH Function returns the length of the string passed.

SELECT LENGTH('tech honey')
FROM dual;

Above mentioned SQL LENGTH Function will return ‘10’ as length of the string.


Oracle PL/SQL LENGTH Function – Use with NULL Example

SQL LENGTH Function can accept NULL as a parameter.

For example the SQL query below returns the length of NULL parameter.

SELECT LENGTH(NULL) "Oracle LENGTH Function"
FROM dual;

Above mentioned Oracle LENGTH Function will return ‘NULL’.


Oracle PL/SQL LENGTH Function – Zero Length String Example

Oracle LENGTH Function can also accept a string of 0 length.

For example the query below returns the length of a string with 0 length.

SELECT LENGTH('')
FROM dual;

Above mentioned PL/SQL LENGTH Function will return ‘NULL’.


Tagged , , , , , , , , , , , . Bookmark the permalink.