The Length () function in Oracle cannot distinguish between Chinese and English characters. it can only obtain the number of characters but not the number of bytes. in many cases, you must first perform a check when inserting a string to a field, this prevents the string length from exceeding the defined length of the field. Generally, this check is executed in the application. you can use this small function on the database server.
The Length () function in Oracle cannot distinguish between Chinese and English characters. it can only obtain the number of characters but not the number of bytes. in many cases, you must first perform a check when inserting a string to a field, this prevents the string length from exceeding the defined length of the field. Generally, this check is executed in the application. you can use this small function on the database server.
The Length () function in Oracle cannot distinguish between Chinese and English characters. it can only obtain the number of characters but not the number of bytes. in many cases, you must first perform a check when inserting a string to a field, this prevents the string length from exceeding the defined length of the field. Generally, this check is executed in the application, using this small function, we can detect the fields to be inserted at the end.
Create or replace function f_henry_GetStringLength (pv_String in varchar2) return integer is
Result integer;
I number;
Begin
Result: = 0;
If length (pv_String) = 0 then
Return (Result );
End if;
For I in 1 .. length (pv_String) loop
If ascii (substr (pv_String, I, 1) <256 then
Result: = Result + 1;
Else
Result: = Result + 2;
End if;
End loop;
Return (Result );
End f_henry_GetStringLength;
*********** ****************/
SQL> select length ('Ah $ @ oii) from dual;
LENGTH ('Ah $ @ OII sends a large value ')
-----------------------
9
SQL> select f_henry_GetStringLength ('Ah $ @ oii) from dual;
F_HENRY_GETSTRINGLENGTH ('Ah $ @ O
------------------------------
13