我可以使用什么 SQL 服务器函数来获取 nvarchar(max) 列的字符或字节长度?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36585/
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-08-31 23:11:27  来源:igfitidea点击:

What SQL-server function can I use to get the character or byte length of a nvarchar(max) column?

sqlsql-server

提问by Jim

I have a column which is of type nvarchar(max). How do I find the length of the string (or the number of bytes) for the column for each row in the table?

我有一个 nvarchar(max) 类型的列。如何找到表中每一行的列的字符串长度(或字节数)?

回答by Brian R. Bondy

SELECT LEN(columnName) AS MyLength FROM myTable

SELECT LEN(columnName) AS MyLength FROM myTable

回答by Joseph Pecoraro

If you want to find out the max there should be a way for you to get the schema of the table. Normally you can do something like SHOW COLUMNSin SQL or a DESCRIBEstyle command. In a mysql shell that can be shortened to:

如果您想找出最大值,应该有一种方法可以让您获得表的架构。通常,您可以在 SQL 中执行SHOW COLUMNSDESCRIBE样式命令之类的操作。在可以缩短为的 mysql shell 中:

desc tablename;

Then if you want to determine the length of a string there is normally a function like LENGTH(for bytes)or CHAR_LENGTH(for characters).

然后,如果您想确定字符串的长度,通常有一个函数,如LENGTH (用于字节)CHAR_LENGTH (用于字符)

SELECT *, LENGTH(fieldname) AS len FROM tablename

回答by sivasankar

SELECT LEN(columnName) AS MyLength FROM myTable

I used this query for my table. It displays the size of each row in a particular column.

我将此查询用于我的表。它显示特定列中每一行的大小。

I need that field name size maximum it allow the characters.

我需要该字段名称的最大大小,它允许字符。