Created
March 23, 2017 07:38
-
-
Save composite/fe52d894899cff1be4b65f2d89a3bfdc to your computer and use it in GitHub Desktop.
The freaking alternative LENGTHB function for Oracle unicode environment. if one unicode calculates 3 bytes, this function will give you returning 2 bytes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE OR REPLACE FUNCTION FN_LENGTHK(PS_STR IN VARCHAR2) RETURN NUMBER IS | |
| V_STR_LEN NUMBER; | |
| V_STR_CHR VARCHAR2(3); | |
| V_RES_LEN NUMBER; | |
| /****************************************************************************** | |
| NAME: FN_LENGTHK | |
| PURPOSE: LENGTHB와 동일하나 유니코드 특성상 한글 3바이트로 계산하기 때문 | |
| 에 2바이트로 처리하여 출력하기 위한 공통 함수 | |
| 유니코드 만세! | |
| REVISIONS: | |
| Ver Date Author Description | |
| --------- ---------- --------------- ------------------------------------ | |
| 1.0 2017/03/23 Composite 1. Created this function. | |
| NOTES: | |
| Automatically available Auto Replace Keywords: | |
| Object Name: FN_LENGTHK | |
| Sysdate: 2017/03/23 | |
| Date and Time: 2017/03/23, 오후 4:23:25, and 2017/03/23 오후 4:23:25 | |
| Username: Composite | |
| Table Name: | |
| ******************************************************************************/ | |
| BEGIN | |
| V_RES_LEN := 0; | |
| V_STR_LEN := LENGTH(PS_STR); | |
| IF V_STR_LEN > 0 THEN | |
| FOR i IN 1..V_STR_LEN | |
| LOOP | |
| V_STR_CHR := SUBSTR(PS_STR,i,1) ; | |
| V_RES_LEN := V_RES_LEN + CASE WHEN LENGTHB(V_STR_CHR) > 1 THEN 2 ELSE 1 END; | |
| END LOOP; | |
| END IF; | |
| RETURN V_RES_LEN; | |
| END FN_LENGTHK; | |
| / |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment