Subject | RE: [ib-support] declare cursor |
---|---|
Author | Jordi Gálvez |
Post date | 2001-04-20T07:00:21Z |
Paul,
CREATE PROCEDURE PROCEDIM
AS
DECLARE VARIABLE rdno integer;
DECLARE VARIABLE valor integer;
BEGIN
DECLARE cur CURSOR FOR
SELECT * FROM "empleado"
FOR UPDATE OF "numero";
OPEN cur;
FOR SELECT "dni"
FROM "empleado"
INTO :RDNO
DO
BEGIN
VALOR = GEN_ID("GEN_numero",1);
FETCH cur;
UPDATE "empleado" SET "empleado"."numero" = :VALOR
WHERE CURRENT OF cur;
END
CLOSE cur;
END
but I get the error in the first "DECLARE cur CURSOR" statement :
Invalid token.
Dynamic SQL Error.
SQL error code = -104.
Token unknown - line 8, char 3.
DECLARE.
the purpose of this procedure is, with an existing table I added a new blank
column "numero" and I want to fill it with a generator. I try to use the
cursor to get every row and fill this field with the current value of the
generator (I also don't know why the INTO statement is necesary in FOR
SELECT statement so I have to use a dummy variable... I'm very newbie in IB
;)
Jordi
>DECLARE CURSOR is an embedded SQL construct. Should work fine if >you areusing
>embedded SQL. Wont work at all if you are not.the stored procedure I try to create is something like :
>
>As Helen says, if you are working within stored procedures use the FOR
>SELECT DO
>style open a cursor onto
>each row and process it.
CREATE PROCEDURE PROCEDIM
AS
DECLARE VARIABLE rdno integer;
DECLARE VARIABLE valor integer;
BEGIN
DECLARE cur CURSOR FOR
SELECT * FROM "empleado"
FOR UPDATE OF "numero";
OPEN cur;
FOR SELECT "dni"
FROM "empleado"
INTO :RDNO
DO
BEGIN
VALOR = GEN_ID("GEN_numero",1);
FETCH cur;
UPDATE "empleado" SET "empleado"."numero" = :VALOR
WHERE CURRENT OF cur;
END
CLOSE cur;
END
but I get the error in the first "DECLARE cur CURSOR" statement :
Invalid token.
Dynamic SQL Error.
SQL error code = -104.
Token unknown - line 8, char 3.
DECLARE.
the purpose of this procedure is, with an existing table I added a new blank
column "numero" and I want to fill it with a generator. I try to use the
cursor to get every row and fill this field with the current value of the
generator (I also don't know why the INTO statement is necesary in FOR
SELECT statement so I have to use a dummy variable... I'm very newbie in IB
;)
Jordi