liquido
Power Member
Estou com dificuldade em utilizar ciclos FOR em PL\SQL (no Postgres)..queria fazer um ciclo por exemplo a utilizar os valores de uma coluna específica de uma tabela mas obtenho os seguintes erros:
[FONT=courier new,monospace]as[/FONT]
[FONT=courier new,monospace] $$[/FONT]
[FONT=courier new,monospace] declare n numeric(20,2) default 0;[/FONT]
[FONT=courier new,monospace] begin[/FONT]
[FONT=courier new,monospace] for r as[/FONT]
[FONT=courier new,monospace] select balance from account[/FONT]
[FONT=courier new,monospace] where branch_name = 'Perryridge'[/FONT]
[FONT=courier new,monospace] do[/FONT]
[FONT=courier new,monospace] set n = n + r.balance[/FONT]
[FONT=courier new,monospace] end for;[/FONT]
[FONT=courier new,monospace] return n;[/FONT]
[FONT=courier new,monospace] end [/FONT]
[FONT=courier new,monospace] $$[/FONT]
[FONT=courier new,monospace] language plpgsql;[/FONT]
e recebo:
[FONT=courier new,monospace]psql:c:/lab6.sql:80: ERROR: syntax error at or near "as"[/FONT]
[FONT=courier new,monospace] LINE 12: for r as[/FONT]
[FONT=courier new,monospace] ^[/FONT]
tentei fazer um ciclo sobre os nomes das agencias:
[FONT=courier new,monospace] for branch_name in select * from branch loop[/FONT]
[FONT=courier new,monospace](..)[/FONT]
[FONT=courier new,monospace]end loop;[/FONT]
[FONT=courier new,monospace]psql:c:/lab6.sql:78: ERROR: loop variable of loop over rows must be a record or row variable or list of scalar variables at or near "loop" [/FONT]
[FONT=courier new,monospace]LINE 13: for branch in select * from branch loop
será que alguém me pode dar alguma dica?
obrigado!
[/FONT]
[FONT=courier new,monospace]as[/FONT]
[FONT=courier new,monospace] $$[/FONT]
[FONT=courier new,monospace] declare n numeric(20,2) default 0;[/FONT]
[FONT=courier new,monospace] begin[/FONT]
[FONT=courier new,monospace] for r as[/FONT]
[FONT=courier new,monospace] select balance from account[/FONT]
[FONT=courier new,monospace] where branch_name = 'Perryridge'[/FONT]
[FONT=courier new,monospace] do[/FONT]
[FONT=courier new,monospace] set n = n + r.balance[/FONT]
[FONT=courier new,monospace] end for;[/FONT]
[FONT=courier new,monospace] return n;[/FONT]
[FONT=courier new,monospace] end [/FONT]
[FONT=courier new,monospace] $$[/FONT]
[FONT=courier new,monospace] language plpgsql;[/FONT]
e recebo:
[FONT=courier new,monospace]psql:c:/lab6.sql:80: ERROR: syntax error at or near "as"[/FONT]
[FONT=courier new,monospace] LINE 12: for r as[/FONT]
[FONT=courier new,monospace] ^[/FONT]
tentei fazer um ciclo sobre os nomes das agencias:
[FONT=courier new,monospace] for branch_name in select * from branch loop[/FONT]
[FONT=courier new,monospace](..)[/FONT]
[FONT=courier new,monospace]end loop;[/FONT]
[FONT=courier new,monospace]psql:c:/lab6.sql:78: ERROR: loop variable of loop over rows must be a record or row variable or list of scalar variables at or near "loop" [/FONT]
[FONT=courier new,monospace]LINE 13: for branch in select * from branch loop
será que alguém me pode dar alguma dica?
obrigado!
[/FONT]