通过查询JSON列从表中选择所有记录
我想通过查询以字符串格式存储JSON的特定列来选择表中的所有记录。
查询应仅通过检查包含文本的JSON字符串的值(而不是键)。
列中的JSON可能对两个不同的记录看起来如下:
{
"title": "Test Coupon for Test Data Initializer",
"value": "$100",
"tag": "Test Coupon",
"description": "Test Description",
"expire": "10",
"disclaimer": "NOT VALID"
}
{
"title": "Second Record",
"value": "$40",
"tag": "Initializer",
"description": "Test Description",
"expire": "25",
"disclaimer": "Disclaimer"
}
我想查询本列中的所有JSON的所有值,该列将匹配或包含文本并返回找到匹配的记录。
例如,如果我发送文本“初始化程序”,则应看到第一个JSON包含title
中的“ initializer”,而第二个JSON将其包含在tag
中。 必须返回这两个记录
因此,
SELECT *
FROM tbl
WHERE JSON_VALUE(JSON_COLUMN, '$.*') = '%Initializer%'
I want to select all the records in a table by querying a specific column which stores a JSON in string format.
The query should match only the values (not keys) of the JSON string by checking if it contains a text.
The JSON in the column might look like the following for two different records:
{
"title": "Test Coupon for Test Data Initializer",
"value": "$100",
"tag": "Test Coupon",
"description": "Test Description",
"expire": "10",
"disclaimer": "NOT VALID"
}
{
"title": "Second Record",
"value": "$40",
"tag": "Initializer",
"description": "Test Description",
"expire": "25",
"disclaimer": "Disclaimer"
}
I want to query all the values of the JSON in this column which will match or contain a text and return the records which have found a match.
For e.g. if I send the text "Initializer", it should see that the first JSON contains "Initializer" in title
and the second JSON contains it in tag
. Therefore both records must be returned
I'm not too familiar with the SQL JSON functions and this is what I have so far (not working)
SELECT *
FROM tbl
WHERE JSON_VALUE(JSON_COLUMN, '$.*') = '%Initializer%'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
OpenJSON
:You can use
OPENJSON
: