在MS SQL Server 2016,已經支持JSON處理。 執行下麵代碼,將獲取ms sql server對象類型以及其說明: IF OBJECT_ID('tempdb.dbo.#json_type') IS NOT NULL DROP TABLE #json_type CREATE TABLE ...
在MS SQL Server 2016,已經支持JSON處理。
執行下麵代碼,將獲取ms sql server對象類型以及其說明:
IF OBJECT_ID('tempdb.dbo.#json_type') IS NOT NULL DROP TABLE #json_type CREATE TABLE #json_type ( [type] TINYINT, [data_type] NVARCHAR(30) ) INSERT INTO #json_type ([type],[data_type]) VALUES (0,'null'), (1,'string'), (2,'int'), (3,'true/false'), (4,'array'), (5,'object') SELECT [type],[data_type] FROM #json_typeSource Code
把它寫成一個自定義函數:
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: Insus.NET -- Create date: 2019-05-23 -- Update date: 2019-05-23 -- Description: 獲取存儲過程參數數據 -- ============================================= CREATE OR ALTER FUNCTION [dbo].[svf_JSONDataType] ( @type TINYINT ) RETURNS NVARCHAR(MAX) AS BEGIN RETURN CASE WHEN @type = 0 THEN 'null' WHEN @type = 1 THEN 'string' WHEN @type = 2 THEN 'int' WHEN @type = 3 THEN 'true/false' WHEN @type = 4 THEN 'array' WHEN @type = 5 THEN 'object' END ENDSource Code