2

有可能在 10g 的 PL/SQL 中做这样的事情吗?

if user_is_goat = 1 then
  for item_rec in (select * from pricing_for_goats)
else 
  for item_rec in (select * from pricing_for_non_goats)
end if;
loop
.
.
end loop;

似乎当 oracle 看到“for rec in select * from dual”时,它期望“循环”立即跟随。我在循环中的代码有很多行,我不想维护它的 2 个副本。

4

1 回答 1

2

尝试下面的查询,这将检查是否变量user_is_goat = 1并返回数据,for_goats否则它将返回for_non_goats

for item_rec in 
(
  select * from pricing_for_goats where user_is_goat = 1
  union
  select * from pricing_for_non_goats where user_is_goat <> 1
)
loop
.....
.....
end loop;
于 2012-11-14T22:28:44.943 回答