# 使用 lengthb() 或 length() 計算字串長度 ###### tags: `Oracle` 1. 函式定義: * lengthb(string):計算string所佔的「位元組」 * length(string):計算string所佔的「字數」 2. 一個中文字在Oracle資料庫裡佔多少位元組(bytes)跟資料庫的字符集(編碼)有關,若資料庫編碼為UTF8時,長度為3個位元組(bytes)。 3. 情境: * 若資料庫欄位為 varchar2(100) 時,此時的 100 是指 100 Bytes。 * 字數計算原則:最大長度為 100 Bytes,一個全形中文字算 3 Bytes、一個半形英數字算 1 Byte! * 例如:「108學年度範例活動」,共有三個半形英數字、七個全形中文字,故字數長度為 3 * 1 + 7 * 3 = 24 bytes 4. 相關文章連結 * [Oracle PL/SQL: 判斷資料有無中文字](https://tomkuo139.blogspot.com/2009/02/plsql_04.html)
×
Sign in
Email
Password
Forgot password
or
Sign in via Google
Sign in via Facebook
Sign in via X(Twitter)
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
Continue with a different method
New to HackMD?
Sign up
By signing in, you agree to our
terms of service
.