2012-06-01 47 views
2

我试图写一个简单的存储过程,做一个SELECT语句,但它一直给我一个语法错误,没有任何其他帮助,告诉我是什么错误简单的Informix选择存储过程

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; 

任何理由我应该得到一个语法错误?

+0

尝试将'foreach'更改为'for' – Bohemian

+0

同样处理语法错误 – user867621

回答

2

删除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; 
+0

这就是我可以使用另一个查询来处理它的唯一方法。 当我删除这些是直到得到一个SQL错误。我希望informix会告诉你更多的信息 – user867621

+0

即使我做了一个简单的创建过程测试select * from testing end procedure ..它仍然给我错误 – user867621

+0

删除过程名称中的第一个下划线并再次尝试。 –

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 ; 

的语法foreach语句可从IBM在其Infocenter