2012-06-01 73 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