赞
踩
主要介绍5个函数:
declare @json_str varchar(max)
set @json_str='[
{"key":3,"value1":10,"value2":[{"vv21":13,"vv22":103}],"value3":null},
{"key":4,"value1":15,"value2":[{"vv21":13,"vv22":103}],"value3":"10"},
{"key":7,"value1":20,"value2":[{"vv21":13,"vv22":103}],"value3":"15"}
]'
SELECT IsJson(@json_str) as isjson
用法:Json_Value (value,’$.column’) from openjson(@express)
select JSON_VALUE(value,'$.key') as kk,
JSON_VALUE(value,'$.value1') as value1,
JSON_value(value,'$.value2') as value2,
JSON_QUERY(value,'$.value2') as value2_query,
JSON_VALUE(value,'$.value3') as value3
from openJson(@json_str) -- include_null_values
注:
用法:Json_Query(value,’$.object’) from openjson(@express)
参见2中的示例
用法:json_Modify(value,’$.column’,newValue) from openjson(@express)
如将value1中的值都替换为10086
将value2中嵌套的数组字典进行解析
select JSON_VALUE(value,'$.key') as kk,
JSON_VALUE(value,'$.value1') as value1,
JSON_QUERY(value,'$.value2') as value2_query,
JSON_VALUE(value,'$.value3') as value3,
t.vv21,t.vv22
from openJson(@json_str) as a
cross apply
(
select JSON_VALUE(value,'$.vv21') as vv21,
JSON_VALUE(value,'$.vv22')as vv22
from openJson(Json_Query(value,'$.value2')) as b
) as t
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。