Oracle length() 函数返回错误值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1558172/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 19:11:55  来源:igfitidea点击:

Oracle length() function returning incorrect value

sqloracle

提问by Andreas Wong

I just found some... I don't know what I'd call it but here goes:

我刚刚找到了一些......我不知道我会怎么称呼它,但这里是:

SELECT part_num, 
       length(trim(part_num)) 
  FROM part_programs 
 WHERE rownum <= 10;

...results:

...结果:

PART_NUM        LENGTH(TRIM(PART_NUM))
--------------- ----------------------
THAB256         8
THA1256674      11
THA1256674GU    13
THA1257141      11
THA1257141FR    13
THA1257141FR1   14
THA1257141TD    13
THA2002013      11
THA2002013MI    13
THA2002013MI1   14

The returned integer from length() call actually returns 1 + realLength of the values.

length() 调用返回的整数实际上返回值的 1 + realLength。

I'm not sure where to begin, anyone care to shed a light?

我不知道从哪里开始,有人愿意透露一下吗?

回答by PaulJ

Try looking at the detail of the field by using the built in DUMP function

尝试使用内置的 DUMP 函数查看字段的详细信息

SELECT part_num,
       length(trim(part_num)),
       dump( trim( part_num ) )
  FROM part_programs  
 WHERE rownum <= 10;

This will return data like

这将返回类似的数据

Typ=96 Len=6: 79,114,97,99,108,101

from this query

从这个查询

SELECT dump( 'Oracle' ) from dual

回答by Ron Savage

You probably have a non-visible character (like a CR) on the end of those part_nums that TRIM() does not remove.

在 TRIM() 不会删除的那些 part_nums 的末尾,您可能有一个不可见的字符(如 CR)。

Just a guess. :-)

只是一个猜测。:-)

Try bracketing them with '[' || part_num || ']' in the select and see if you notice some extra white-space on either side of the field.

尝试用 '[' || 将它们括起来 part_num || ']' 在选择中,看看您是否注意到字段两侧有一些额外的空白。