HTTP_GET is a Table Function and have to be specified within the FROM Clause in a SELECT Statement.
A SELECT Statement can only return a single table/result set.
So if you need to return multiple Result Sets, you have to code multiple Cursors, one for each HTTP_GET API you want to access.
How ever I'd suggest to ask yourself if you really need multiple result sets or if it would not possible to join the (decomposed) results in a single statement (may be with multiple CTEs) and then return this single statement.
On the other side I'd also check, also for the solution you already have, if it would not be better to create a UDTF instead of a stored procedure (returning a result set)
Birgitta
------------------------------
Birgitta Hauser
Database and Software Engineer
Selfemployed - Modernization-Education-Consulting on IBM i
Kaufering
+49 170 5269964
------------------------------
Original Message:
Sent: Mon September 19, 2022 12:43 PM
From: Amy Vozza
Subject: HTTP_GET in SQL Stored Procedure - Multiple Result Sets
I'm working on an SQL stored procedure that uses JSON_TABLE and HTTP_GET to call an API and return some data. The API returns one result set and the JSON_TABLE/HTTP_GET works fine for that in the SQL stored procedure. I'm trying to code it now for if the API in the HTTP_GET could return multiple result sets by using a cursor and/or a common table expression. Can someone point me to an example for coding that or give me any suggestions on the best way to handle multiple result sets returned from HTTP_GET in an SQL stored procedure?
------------------------------
Amy Vozza
------------------------------
#SQL