搞不懂了:谁能帮忙解释一下oracle中的 lengthb ?

gaojianbin1313 2007-07-16 10:57:08
在我的机子上执行:
select lengthb('新') from dual
结果是:3

执行
select lengthb('新人') from dual
结果是:6

对于这样的结果很不解 ,我查询资料说lengthb方法是求的字节长度,
应该是2才对!

请高手指点~~~~~~
...全文
250 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
gelyon 2010-11-01
  • 打赏
  • 举报
回复
这根你系统设置有关,一个中文占几个字节。。。
一般是一个中文字占三个字节
lengthb()算的就是字节长度
wangt1103 2010-11-01
  • 打赏
  • 举报
回复
你的那第一个好像有个半角空格吧。
wangchao1982 2007-12-19
  • 打赏
  • 举报
回复
字符集这种东西最可恨了.
wangchao1982 2007-12-19
  • 打赏
  • 举报
回复
应该是 4 和6才对
临摹 2007-07-16
  • 打赏
  • 举报
回复
数据库字符集的问题utf-8的中文字符占用3个字节,gbk的中占2个字节
gaojianbin1313 2007-07-16
  • 打赏
  • 举报
回复
天啊 怎么会这样?
我更加疑惑了!
和系统有关系?我的系统现在是windowsxp 专业英文版,有关系吗?
WangZWang 2007-07-16
  • 打赏
  • 举报
回复
--我的机子上执行等于 4 ,是求字节的长度
select lengthb('新人') as len from dual

Len
----
4
--此函数默认返回汉字拼音的首字母,第二个参数不为空则返回全拼。 create or replace function f_getFirstOrFullSpell(p_cnStr In varchar2,p_sign In number default null) return varchar2 as lv_spell varchar2(200); lv_temp Varchar2(10); lv_char varchar2(10); --lv_bytes varchar2(100); li_bytes Integer; --li_pos Integer; begin if p_cnStr is null then return ''; end if; for i In 1..length(p_cnStr) loop lv_char:=substr(p_cnStr,i,1); if lengthb(lv_char) = 1 then lv_spell:=lv_spell||lv_char; elsif lengthb(lv_char) = 2 then --Select replace(substrb(dump(lv_char,1010),instrb(dump(lv_char,1010),'ZHS16GBK:')),'ZHS16GBK: ','') Into lv_bytes from dual; --li_pos:=instr(lv_bytes,','); --li_bytes:=substr(lv_bytes,1,li_pos-1)*256+substr(lv_bytes,li_pos+1)-256*256; Select ascii(lv_char)-256*256 Into li_bytes From dual; select max(spell) Into lv_temp from table(f_getSpellcode) where code<=li_bytes; if p_sign is null then lv_spell:=lv_spell||substr(lv_temp,1,1); else lv_spell:=lv_spell||lv_temp; end if; elsif lengthb(lv_char) = 3 then --Select replace(substrb(dump(convert(lv_char,'ZHS16GBK','UTF8'),1010),instrb(dump(convert(lv_char,'ZHS16GBK','UTF8'),1010),'UTF8:')),'UTF8: ','') --Into lv_bytes from dual; --li_pos:=instr(lv_bytes,','); --li_bytes:=substr(lv_bytes,1,li_pos-1)*256+substr(lv_bytes,li_pos+1)-256*256; Select ascii(lv_char)-256*256 Into li_bytes From dual; select max(spell) Into lv_temp from table(f_getSpellcode) where code<=li_bytes; if p_sign is null then lv_spell:=lv_spell||substr(lv_char,1,1); else lv_spell:=lv_spell||lv_char; end if; end if; end loop; return lv_spell; end; --hanjs,07-10-24,此函数默认返回汉字拼音的首字母,第二个参数不为空则返回全拼。

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧