1) What IDS version?
2) You are written an ESQL/C style over SPL ... never will work...
If you work with IDS before 11.50 , you must use FOREACH can't use PREPARE+DECLARE+FETCH .
If you use IDS 11.50 this is the right syntax, this command already allowed, check the manual:
Usage.
your code with corrections...
Code:
#Using DECLARE (works only in IDS 11.50)
#tested in IDS 11.50 UC5
create temp table ent_type_def (name char(10), ent_type_id int);
Temporary table created.
CREATE PROCEDURE test()
BEGIN
DEFINE v_ent_type_id INTEGER;;
CREATE TEMP Table entities(name varchar(64));;
PREPARE s_ent_types FROM "Select ent_type_id from ent_type_def for read only" ;;
DECLARE c_ent_types CURSOR FOR s_ent_types;;
Open c_ent_types;;
FETCH c_ent_types into v_ent_type_id;;
WHILE SQLCODE == 0
INSERT INTO entities
select name
from ent_type_def
where ent_type_id = v_ent_type_id;;
FETCH c_ent_types into v_ent_type_id;;
END WHILE;;
--For what is this SELECT???
--Select name from entities;
END;;
END PROCEDURE;
Routine created.
;
Database closed.