数据库sql创建标量值函数_使用JSON_VALUE()从JSON数据中提取标量值

本文介绍了如何使用SQL Server的JSON_VALUE()函数从JSON数据中提取标量值。讨论了JSON的基本概念,JSON_VALUE()的语法,以及通过多个示例展示了如何在JSON数据中搜索键值、处理数组和嵌套数据。此外,还对比了LAX和STRICT路径模式的区别。
摘要由CSDN通过智能技术生成

数据库sql创建标量值函数

In this article, we will explore JSON_VALUE() function in SQL Server to extract scalar values from JSON data.

在本文中,我们将探索SQL Server中的JSON_VALUE()函数,以从JSON数据中提取标量值。

JSON简介 (Introduction to JSON)

JSON is an acronym for “JavaScript Object Notation”. It is a lightweight data exchange language. If you are familiar with XML, it is a bit hard to understand. You can easily interpret JSON formatted data using its key-value pair.

JSON是“ JavaScript对象表示法”的缩写。 它是一种轻量级的数据交换语言。 如果您熟悉XML,将很难理解。 您可以使用其键值对轻松解释JSON格式的数据。

JSON is a popular language and many NoSQL databases such a Couchbase, AWS DynamoDB. It is popular in modern web and mobile applications.

JSON是一种流行的语言,它是许多NoSQL数据库,例如Couchbase,AWS DynamoDB。 它在现代Web和移动应用程序中很流行。

SQL Server 2016 and later supports JSON format data. You should know JSON format and work with JSON data in SQL Server. It also creates a bridge between a relational database and NoSQL systems.

SQL Server 2016及更高版本支持JSON格式数据。 您应该了解JSON格式,并在SQL Server中使用JSON数据。 它还在关系数据库和NoSQL系统之间建立了桥梁。

SQL Server provides various built-in-functions to parse, read, transform, and convert JSON objects. You can also format the T-SQL results in the JSON format. You can go through article category k in SQLShack to understand more details about it.

SQL Server提供了各种内置函数来解析,读取,转换和转换JSON对象。 您也可以使用JSON格式格式化T-SQL结果。 您可以在SQLShack中浏览文章类别k,以了解有关它的更多详细信息。

You can refer to the following image from Microsoft docs to understand the interoperability between SQL table and JSON.

您可以参考Microsoft文档中的以下图像,以了解SQL表和JSON之间的互操作性。

We have the following JSON functions in SQL Server:

我们在SQL Server中具有以下JSON函数:

  • ISJSON(): It checks whether we have a valid JSON or not ISJSON():它检查我们是否具有有效的JSON
  • JSON_VALUE(): We can extract a scalar value from the JSON string. We will explore this function in detail in this article JSON_VALUE():我们可以从JSON字符串中提取标量值。 我们将在本文中详细探讨此功能
  • JSON_QUERY: We can extract an array or string from the JSON_QUERY() output JSON_QUERY:我们可以从JSON_QUERY()输出中提取数组或字符串
  • JSON_MODIFY(): We can modify a value in the JSON Data using this JSON-MODIFY() function JSON_MODIFY():我们可以使用此JSON-MODIFY()函数修改JSON数据中的值

Overview of built-in JSON support

JSON_VALUE()的语法 (Syntax of JSON_VALUE())

JSON_VALUE ( expression ,[Path Mode] JSON_path )

JSON_VALUE(表达式,[路径模式] JSON_path)

  • Expression: It is a variable or column containing a JSON string. It should be a valid expression, and else it returns an error 表达式 :它是包含JSON字符串的变量或列。 它应该是一个有效的表达式,否则返回错误
  • JSON_Path: It is the location of a scalar value in the JSON string JSON_Path:这是JSON字符串中标量值的位置
  • Path mode: It is an optional argument. We can specify the 路径模式:这是一个可选参数。 我们可以在这种模式下指定lax or 宽松strict value in this mode.
  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值