Ваш оператор INSERT неверен - разное количество столбцов (6) и значений (4).Что вы получаете именно в таблице LOG_TEST?
CREATE OR REPLACE PROCEDURE LOG_TEST (
IN QUERY VARCHAR(24576)
, IN LOGTBL_VAR VARCHAR(20)
)
SPECIFIC LOG_TEST
BEGIN
DECLARE SQLCODE INTEGER DEFAULT 0;
DECLARE SQLSTATE CHAR(5) DEFAULT '00000';
DECLARE V_ERRORMSG VARCHAR(2048) DEFAULT '';
DECLARE V_SQLCODE INTEGER DEFAULT 0;
DECLARE V_SQLSTATE CHAR(5) DEFAULT '00000';
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION, SQLWARNING,NOT FOUND
BEGIN
GET DIAGNOSTICS EXCEPTION 1 V_ERRORMSG = MESSAGE_TEXT;
VALUES(SQLSTATE,SQLCODE) INTO V_SQLSTATE, V_SQLCODE;
END;
EXECUTE IMMEDIATE QUERY;
PREPARE STMT_INS FROM 'INSERT INTO '||LOGTBL_VAR||'(QUERY, SQL_CODE, SQL_STATE, ERROR_MSG) VALUES (?,?,?,?)';
EXECUTE STMT_INS USING QUERY, V_SQLCODE, V_SQLSTATE, V_ERRORMSG;
END@
CREATE TABLE LOG_TEST(QUERY VARCHAR(1000), SQL_CODE INT, SQL_STATE CHAR(5), ERROR_MSG VARCHAR(1000)) IN USERSPACE1@
CALL LOG_TEST('DELETE FROM LOG_TEST - WRONG QUERY', 'LOG_TEST')@
SELECT * FROM LOG_TEST@
Если вы хотите запустить операторы SELECT и получить результаты, тогда:
CREATE OR REPLACE PROCEDURE LOG_TEST (
IN QUERY VARCHAR(24576)
, IN LOGTBL_VAR VARCHAR(20)
, OUT RES INT
)
SPECIFIC LOG_TEST
BEGIN
DECLARE SQLCODE INTEGER DEFAULT 0;
DECLARE SQLSTATE CHAR(5) DEFAULT '00000';
DECLARE V_ERRORMSG VARCHAR(2048) DEFAULT '';
DECLARE V_SQLCODE INTEGER DEFAULT 0;
DECLARE V_SQLSTATE CHAR(5) DEFAULT '00000';
DECLARE V_QUERY VARCHAR(24576);
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION, SQLWARNING,NOT FOUND
BEGIN
GET DIAGNOSTICS EXCEPTION 1 V_ERRORMSG = MESSAGE_TEXT;
VALUES(SQLSTATE,SQLCODE) INTO V_SQLSTATE, V_SQLCODE;
END;
SET V_QUERY='SET (?) = ('||REPLACE(QUERY, '''', '''''')||')';
PREPARE STMT_SEL FROM V_QUERY;
EXECUTE STMT_SEL INTO RES;
PREPARE STMT_INS FROM 'INSERT INTO '||LOGTBL_VAR||'(QUERY, SQL_CODE, SQL_STATE, ERROR_MSG) VALUES (?,?,?,?)';
EXECUTE STMT_INS USING QUERY, V_SQLCODE, V_SQLSTATE, V_ERRORMSG;
END@