Oracle UDFs f_henry_GetStringLength-mysql tutorial

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.