提问人:Yace64DZFT 提问时间:10/6/2023 更新时间:10/6/2023 访问量:62
SQL Loop Salesforce 下载
SQL Loop Salesforce Download
问:
我有一个循环,它根据查询参数从Salesforce下载数据
这可以下载大量数据;有没有办法让它更有效率?
它是一个存储过程,它获取尽可能多的 json (2000),然后将它们全部组合起来,并将其从解释和粘贴到表中的过程中传递出去
代码如下
SET @url = @baseUrl + '/services/data/v58.0/query/?q=' + @query
SET @authHeader = CONCAT('Bearer ', (SELECT TOP 1 whatVal FROM TKTable))
WHILE @responseText NOT LIKE '%,"done":true,%' AND @loopNo<=300
BEGIN
PRINT ''
PRINT 'LOOP NUMBER: ' + CONVERT(varchar(3),@loopNo)
PRINT ''
PRINT ''
PRINT 'URL: ' +@url
PRINT ''
IF @responseText = 'First Loop' EXEC sp_OACreate 'MSXML2.XMLHttp.6.0', @internalToken OUT;
EXEC sp_OAMethod @internalToken, 'open', NULL, 'get', @url, 'false'
EXEC sp_OAMethod @internalToken, 'setRequestHeader', NULL, 'Authorization', @authHeader
EXEC sp_OAMethod @internalToken, 'send', NULL, ''
DELETE FROM @json
INSERT into @json (response) exec sp_OAGetProperty @internalToken, 'responseText'
SET @responseText=(SELECT TOP 1 response FROM @json)
PRINT ''
PRINT 'DOWNLOADED: ' + @responseText
SET @url = @baseURL +
(SELECT nextRecordsUrl FROM openjson(@responseText) WITH
(
nextRecordsUrl varchar(255) '$.nextRecordsUrl'
)
)
SET @jsonString = ISNULL(@jsonString,'') + (SELECT STRING_AGG([value],',') FROM openjson(@responseText, '$.records')) + ','
SET @loopNo = @loopNo+1
END
SET @jsonString = LEFT(@jsonString,LEN(@jsonString)-1) --Remove extra comma
SET @outputJson = '[ ' + @jsonString + ']'
--Close the connection.
EXEC sp_OADestroy @internalToken;
我尝试过但失败的一些想法:
-重复使用@internalToken - 抓住@responseText而不把它放在桌子上
答: 暂无答案
评论