I have created sql that I tested out using microsoft sql server (since I'm more familiar with it) and it works. When I try to run it in db2, I'm running into problems with a cursor definition. I'm not sure if I need this in a stored procedure, or there's some other problem with what I'm trying to do. I'm using advanced query tool to run my sql statement. Here's part of my code:
DECLARE GLOBAL TEMPORARY TABLE SESSION.TEMP_org
(
agmt_id decimal(15),
rol_plyr_anchr_id decimal(15),
depth_fm_parnt smallint,
full_nm varchar(100)
);
--load temp_org
DECLARE policy_cursor CURSOR
FOR SELECT rol_plyr_anchr_id FROM SESSION.TEMP_pol;
OPEN policy_cursor;
The declare temp table is okay, but it doesn't seem to like my declare of my policy_cursor. I'm receiving the following error message:
42601(-104)[IBM][CLI Driver][DB2/AIX64] SQL0104N An unexpected token "DECLARE POLICY_CURSOR CURSOR FOR SELECT" was found following "BEGIN-OF-STATEMENT". Expected tokens may include: "<space>". SQLSTATE=42601
Any suggestions would be much appreciated. I am a novice at DB2.
Thanks, Yolanda