【问题标题】:Simple informix select stored procedure简单的informix选择存储过程
【发布时间】:2012-06-01 13:51:09
【问题描述】:

我正在尝试编写一个执行 select 语句的简单存储过程,但它一直给我一个语法错误,而没有任何其他帮助告诉我错误是什么

create procedure _this_is_it(this CHAR(3), that CHAR(4), other CHAR(3))
foreach select * from table 
where column1 = this and
column2 = that and
column3 = other
end foreach
end procedure;

我应该得到语法错误的任何原因?

【问题讨论】:

  • 尝试将foreach更改为for
  • 同样处理语法错误

标签: sql stored-procedures informix


【解决方案1】:

删除foreach_ 作为首字母,并在选择末尾添加;

create procedure this_is_it(this CHAR(3), that CHAR(4), other CHAR(3))

select * from table 
where column1 = this and
column2 = that and
column3 = other;

end procedure;

【讨论】:

  • 这是我可以让它与我使用的另一个查询一起工作的唯一方法。当我删除那些 Is 直到得到一个 sql 错误。我希望informix 能告诉你更多信息
  • 即使我做了一个简单的创建过程 test select * from testing end procedure.. 它仍然给我错误
  • 把过程名的第一个下划线去掉,再试一次。
  • @user867621 检查我修改后的答案。
  • 这确实摆脱了 sql 错误...现在它要求我将其放入临时表中...非常感谢
【解决方案2】:

如果你想在 foreach 循环中执行一些处理,你必须 SELECT INTO 变量。所以你的代码会变成:

drop procedure if exists _this_is_it ;
drop table if exists this_table ;
create temp table this_table(column1 CHAR(3), column2 CHAR(4), column3 CHAR(3))
with no log ;
insert into this_table values("A","B","C") ;

create procedure _this_is_it(this CHAR(3), that CHAR(4), other CHAR(3))
returns CHAR(10) AS something

define f_this CHAR(3) ;
define f_that CHAR(4) ;
define f_other CHAR(3) ;

foreach
select * into f_this, f_that, f_other
from this_table
where column1 = this and
column2 = that and
column3 = other

return f_this||f_that||f_other WITH RESUME ;

end foreach
end procedure;

grant execute on _this_is_it to public;
execute procedure _this_is_it("A","B","C") ;

drop procedure if exists _this_is_it ;
drop table if exists this_table ;

IBM 的Infocenter 提供了 FOREACH 语句的语法。

【讨论】:

    猜你喜欢
    • 2011-05-14
    • 1970-01-01
    • 1970-01-01
    • 2012-07-28
    • 1970-01-01
    • 2012-06-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-12
    相关资源
    最近更新 更多