Search code examples
sqlstored-proceduresresultsethsqldbdatabase-cursor

How to pass declared table to procedure as parameter?; How to access inside procedure the result cursor of another procedure?


  1. I want to pass a declared table (or a cursor) to a procedure (or a function) as a parameter. For example, in the following code, I want to pass the declared table temp_table to the procedure calculate_something_2 as a parameter.

  2. I want to get inside a procedure the result cursor of another procedure. For example, in the following code, I want to get inside calculate_something_1 the result cursor of calculate_something_2.

I have seen similar things being done in other databases, but is it possible to do any of these in HSQLDB?

I have looked at the documentation but could not find any way to do it.

The following code is the basic idea of what I want to achieve. However, it does not work.

create procedure calculate_something_1(in data int)
        modifies sql data
        dynamic result sets 1
    begin atomic

        declare table temp_table (id int, quantity int);

        insert into temp_table values
            (1, 10),
            (2, 20),
            (3, 30);

        declare result_cursor cursor for 
            select id from (call calculate_something_2(temp_table)) where id > 10;
        open result_cursor;
    end;

create procedure calculate_something_2(in t table)
        modifies sql data
        dynamic result sets 1
    begin atomic

        declare result_cursor cursor for 
            select id from t where id > 5;
        open result_cursor;
    end;

Solution

  • It is not possible to pass cursors or tables among PROCEDUREs.

    You can define the shared tables as CREATE GLOBAL TEMPORARY TABLE and reference them in different procedures.