如何在SQL Server 2016中找到json对象的长度?

时间:2018-08-01 13:07:57

标签: sql sql-server

[{"FUNCTION_HIERARCHY_LEVEL":"1","FUNCTION_PRIMARY_INDICATOR":"1","FUNCTION_CODE":"16041049","FUNCTION_DESCRIPTION":"SERVICES","FUNCTION_GLOBAL_CODE":"163554","FUNCTION_GLOBAL_DESCRIPTION":"Internal Services","Function_TYPE":"bbcc","FUNCTION_TYPE_CODE":"ASSIGNED","FUNCTION_TYPE_DESCRIPTION":"Assigned to the Function"},{"FUNCTION_HIERARCHY_LEVEL":"2","FUNCTION_PRIMARY_INDICATOR":"1","FUNCTION_CODE":"16041049","FUNCTION_DESCRIPTION":"SERVICES","FUNCTION_GLOBAL_CODE":"1736","FUNCTION_GLOBAL_DESCRIPTION":"Information Technology","Function_TYPE":"bb","FUNCTION_TYPE_CODE":"ASSIGNED","FUNCTION_TYPE_DESCRIPTION":"Assigned to the Function"},{"FUNCTION_HIERARCHY_LEVEL":"1","FUNCTION_PRIMARY_INDICATOR":"1","FUNCTION_CODE":"16041049","FUNCTION_DESCRIPTION":"SERVICES","FUNCTION_GLOBAL_CODE":"163554","FUNCTION_GLOBAL_DESCRIPTION":"Internal Services","Function_TYPE":"bbcc","FUNCTION_TYPE_CODE":"HE","FUNCTION_TYPE_DESCRIPTION":"Client Service Function Assigned by HR"},{"FUNCTION_HIERARCHY_LEVEL":"2","FUNCTION_PRIMARY_INDICATOR":"1","FUNCTION_CODE":"16041049","FUNCTION_DESCRIPTION":"SERVICES","FUNCTION_GLOBAL_CODE":"1736","FUNCTION_GLOBAL_DESCRIPTION":"Information Technology","Function_TYPE":"bb","FUNCTION_TYPE_CODE":"HE","FUNCTION_TYPE_DESCRIPTION":"Client Service Function Assigned by HR"}]

如果此值存储在某个表的json列中,如何在SQL Server中找到此json的长度?

1 个答案:

答案 0 :(得分:3)

SQL Server没有JSON列数据类型-JSON存储在NVARCHAR列中。

您可以在列上使用LEN(columnname)来获取其长度,以字符为单位,或者 DATALENGTH(columnname)的长度为 bytes NVARCHAR将每个字符存储为两个字节)

当然,这只是返回JSON的字符串表示形式的长度-如果这正是您想要的。否则,您需要更清楚地指定要查找的内容