在 IBM DB2 的存储过程中执行动态 select 查询时出错

Error executing dynamic select query inside a stored procedure in IBM DB2

下面的代码有什么问题?我正在尝试在 DB2 的存储过程中执行动态查询。正在创建我的程序

CREATE PROCEDURE  get_users( in offsetValue integer,
                              in sortCol varchar(20)            
                            )
  SPECIFIC get_users
  LANGUAGE SQL 

  Re:  BEGIN

    DECLARE SELECT_STATEMENT VARCHAR(8000);
    DECLARE SQL_STATEMENT STATEMENT;

    DECLARE c_emp CURSOR FOR SQL_STATEMENT;

    set SELECT_STATEMENT = 'select * from users;';

    PREPARE SQL_STATEMENT FROM SELECT_STATEMENT;

    EXECUTE SQL_STATEMENT; 

    open c_emp;
  END Re

但是当我使用

调用过程时
call get_users(3, 'email_id');

我收到以下错误

SQL Error: DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=;;select * from users;END-OF-STATEMENT, DRIVER=4.24.92

可能出了什么问题?

错误太多... 试试这个:

--#SET TERMINATOR @

CREATE OR REPLACE PROCEDURE  get_users( in offsetValue integer,
                              in sortCol varchar(20)            
                            )
  SPECIFIC get_users
  DYNAMIC RESULT SETS 1
  LANGUAGE SQL 

  Re:  BEGIN
    DECLARE SELECT_STATEMENT VARCHAR(8000);
    DECLARE SQL_STATEMENT STATEMENT;
    DECLARE c_emp CURSOR WITH RETURN FOR SQL_STATEMENT;

    set SELECT_STATEMENT = 'select * from users';
    PREPARE SQL_STATEMENT FROM SELECT_STATEMENT;
    open c_emp;
  END Re
  @