Quantcast
Channel: SCN : Discussion List - SAP HANA Developer Center
Viewing all articles
Browse latest Browse all 6412

Populating temp table from result of procedure

$
0
0

So I am trying to create a procedure with the following logic.

  • Split a delimited string into a (temp) table
  • Iterate the above table to perform an action with each row value.

 

 

The Split function I have is thus :

 

CREATE PROCEDURE "myschema"."SPLIT_TEST"(TEXT nvarchar(4000))

AS

BEGIN

  declare _items nvarchar(100) ARRAY;

  declare _text nvarchar(100);

  declare _index integer;

  _text := :TEXT;

  _index := 1;

 

  WHILE LOCATE(:_text,',') > 0 DO

  _items[:_index] := SUBSTR_BEFORE(:_text,',');

  _text := SUBSTR_AFTER(:_text,',');

  _index := :_index + 1;

  END WHILE;

  _items[:_index] := :_text;

 

  rst = UNNEST(:_items) AS ("items");

  SELECT * FROM :rst;

END;

 

 

Now this works fine to call by itself :  CALL "myschema"."SPLIT_TEST" ('a,c,e,g')

 

 

But I am struggling on how to call this from my main procedure and iterate the results.

I need to insert the results into a temp table; or have SPLIT_TEST return a table object.

 

If using psuedo code, would be something like :

         

CREATE LOCAL TEMPORARY TABLE #temp (

            "txt" nvarchar(128)

);

 

insert into #temp("txt")

CALL "myschema"."SPLIT_TEST" ('a,c,e,g');

 

                  <iterate #temp>

 

 

I hope someone can guide me in the right direction !?!

 

Many Thanks


Viewing all articles
Browse latest Browse all 6412

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>