ISJSON (Transact-SQL)ISJSON (Transact-SQL)
適用範圍:Applies to: SQL Server 2016 (13.x)SQL Server 2016 (13.x)
SQL Server 2016 (13.x)SQL Server 2016 (13.x)
Azure SQL DatabaseAzure SQL Database
Azure SQL DatabaseAzure SQL Database
Azure SQL 受控執行個體Azure SQL Managed Instance
Azure SQL 受控執行個體Azure SQL Managed Instance
Azure Synapse AnalyticsAzure Synapse Analytics
Azure Synapse AnalyticsAzure Synapse Analytics
SQL Server 2016 (13.x)SQL Server 2016 (13.x)
SQL Server 2016 (13.x)SQL Server 2016 (13.x)
Azure SQL DatabaseAzure SQL Database
Azure SQL DatabaseAzure SQL Database
Azure SQL 受控執行個體Azure SQL Managed Instance
Azure SQL 受控執行個體Azure SQL Managed Instance
Azure Synapse AnalyticsAzure Synapse Analytics
Azure Synapse AnalyticsAzure Synapse Analytics
測試字串是否包含有效的 JSON。Tests whether a string contains valid JSON.
Transact-SQL 語法慣例
Transact-SQL Syntax Conventions
語法Syntax
ISJSON ( expression )
引數Arguments
expressionexpression
要測試的字串。The string to test.
傳回值Return Value
若字串包含有效的 JSON,則傳回 1;否則傳回 0。Returns 1 if the string contains valid JSON; otherwise, returns 0. 若 expression 為 null,則傳回 null。Returns null if expression is null.
不會傳回錯誤。Does not return errors.
備註Remarks
ISJSON 不會檢查相同層級中索引鍵的唯一性。ISJSON does not check the uniqueness of keys at the same level.
範例Examples
範例 1Example 1
下列範例會在參數值 @param
包含有效的 JSON 時條件式的執行陳述式區塊。The following example runs a statement block conditionally if the parameter value @param
contains valid JSON.
DECLARE @param <data type>
SET @param = <value>
IF (ISJSON(@param) > 0)
BEGIN
-- Do something with the valid JSON value of @param.
END
範例 2Example 2
下列範例會傳回資料行 json_col
中包含有效 JSON 的資料列。The following example returns rows in which the column json_col
contains valid JSON.
SELECT id, json_col
FROM tab1
WHERE ISJSON(json_col) > 0