我正在尝试创建一个过程,该过程将查询表列以检索表名,并在 proc 中使用它来运行查询以进行选择(如果存在)。如果不存在,则从 systables_growth 表中删除行。
以下是我到目前为止的内容:
CREATE function test_sp();
DEFINE v_tab CHAR(255);
FOREACH SELECT unique(tabname) INTO v_tab from systables_growth
BEGIN
SELECT * FROM v_tab;
ON EXCEPTION IN (-206) -- If no table was found, delete record from systables_growth table
DELETE from systables_growth WHERE tabname = 'v_tab'
END EXCEPTION WITH RESUME;
END
END FOREACH
END function;
创建时收到以下语法错误:
CREATE function test_sp();
DEFINE v_tab CHAR(255);
FOREACH SELECT unique(tabname) INTO v_tab from systables_growth
BEGIN
SELECT * FROM v_tab;
ON EXCEPTION IN (-206) -- If no table was found, delete record from systables_growth table
#^
# 201: A syntax error has occurred.
#
DELETE from systables_growth WHERE tabname = 'v_tab'
END EXCEPTION WITH RESUME;
END
END FOREACH
END function;
我正在尝试定义一些逻辑来查询从表中提取的记录,以运行从提取的表名中进行选择的查询。如果选择说表不存在,那么我希望从表中删除该行。我不知道我是否使用了正确的逻辑。
我不希望该过程生成任何输出,我希望它保持沉默。
我在informix中找到了一个使用存储过程的替代解决方案,它也适用于我: