PostgreSQL:嵌套循环
是否可以在另一个循环中包含一个循环? (嵌套循环)在 postgres 中。类似于下面的内容:
WHILE rowCounter < totalRows LOOP
FETCH NEXT FROM retailerIdCursor INTO retailerID;
--FOR i IN 1..8 LOOP
--WHILE i < 8 LOOP
LOOP
UPDATE sales_fact
SET retailer_id = retailerID
WHERE sales_id = rowCounter;
EXIT WHEN i > 8;
END LOOP;
rowCounter = 1+ rowCounter;
END LOOP;
Is it possible to have a loop within another loop? (nested loops) in postgres. Something similar to below:
WHILE rowCounter < totalRows LOOP
FETCH NEXT FROM retailerIdCursor INTO retailerID;
--FOR i IN 1..8 LOOP
--WHILE i < 8 LOOP
LOOP
UPDATE sales_fact
SET retailer_id = retailerID
WHERE sales_id = rowCounter;
EXIT WHEN i > 8;
END LOOP;
rowCounter = 1+ rowCounter;
END LOOP;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不明白为什么你不能
像弗兰克建议的那样写作。
根据选择 RetailerId 的语句,您甚至可能不需要外循环。
I fail to see why you cannot just write
as Frank has suggested.
Depending on the statement that selects the retailerId, you might not even need the outer loop as well.
你可以查看postgresql文档。
http://www.postgresql.org/docs/current/static /plpgsql-control-structs.html
You can look at postgresql documentation.
http://www.postgresql.org/docs/current/static/plpgsql-control-structures.html