PLSQL | LENGTH2 Function
The PLSQL LENGTH2 function is used for returning the length of the specified string, in other words, it returns the length of char. UCS-2 codepoints is a character encoding standard in which characters are represented by a fixed-length 16 bits (2 bytes). UCS-2 represents a possible maximum of 65, 536 characters, or in hexadecimals from 0000h – FFFFh (2 bytes).
The char accepted by the LENGTH2 function in PLSQL can be of any of the datatypes such as CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB. The value returned by the LENGTH2 function is of datatype NUMBER. If char sent in the parameter has datatype CHAR, then the length includes all trailing blanks. If char is null, then this function returns null.
Syntax:
LENGTH2( string )
Parameters Used:
string – It is used to specify the string whose length you want to find out.
Supported Versions of Oracle/PLSQL:
- Oracle 12c
- Oracle 11g
- Oracle 10g
- Oracle 9i
- Oracle 8i
Example-1:
DECLARE Test_String string(20) := NULL; BEGIN dbms_output.put_line(LENGTH2(Test_String)); END;
Output:
NULL
Example-2:
DECLARE Test_String string(20) := ''; BEGIN dbms_output.put_line(LENGTH2(Test_String)); END;
Output:
NULL
Example-3:
DECLARE Test_String string(20) := ' '; BEGIN dbms_output.put_line(LENGTH2(Test_String)); END;
Output:
1
Example-4:
DECLARE Test_String string(20) := 'Geeksforgeeks'; BEGIN dbms_output.put_line(LENGTH2(Test_String)); END;
Output:
13
Example-5:
DECLARE Test_String string(20) := ' Geeksforgeeks '; BEGIN dbms_output.put_line(LENGTH2(Test_String)); END;
Output:
15
Recommended Posts:
- PLSQL | LN Function
- PLSQL | TAN Function
- PLSQL | ABS Function
- PLSQL | SIN Function
- PLSQL | CHR Function
- PLSQL | LEAST Function
- PLSQL | LOG Function
- PLSQL | EXP Function
- PLSQL | COS Function
- PLSQL | MOD Function
- PLSQL | REMAINDER Function
- PLSQL | SQRT Function
- PLSQL | CURRENT_TIMESTAMP Function
- PLSQL | FLOOR Function
- PLSQL | INSTR2 Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


