oracle 获取列值长度,而不是列最大长度值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13064621/
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
Get column value length, not column max length of value
提问by Buksy
How do I get actual length of value in column?
如何获得列中值的实际长度?
My (oracle) sql command returns maximum length of value that can be inserted in the column instead of real length of value.
我的(oracle)sql 命令返回可以插入列中的值的最大长度,而不是值的实际长度。
How to fix this?
如何解决这个问题?
SQL> SELECT typ, length(t1.typ)
FROM AUTA_VIEW t1;
TYP LENGTH(T1.TYP)
---------- --------------
BMW 10
BMW 10
BMW 10
Ferrari 10
BMW 10
Audi 10
Audi 10
Audi 10
Ferrari 10
Ferrari 10
Mercedes 10
回答by Andreas Fester
LENGTH()
does return the string length (just verified). I suppose that your data is padded with blanks - try
LENGTH()
确实返回字符串长度(刚刚验证)。我想你的数据是用空格填充的 - 试试
SELECT typ, LENGTH(TRIM(t1.typ))
FROM AUTA_VIEW t1;
instead.
反而。
As OraNob
mentioned, another cause could be that CHAR
is used in which case LENGTH()
would also return the column width, not the string length. However, the TRIM()
approach also works in this case.
正如OraNob
所提到的,另一种原因可能是CHAR
在这种情况下,使用LENGTH()
也将返回列的宽度,而不是字符串长度。但是,该TRIM()
方法也适用于这种情况。