plsql - oracle 10g pl/sql 条件for循环选择

标签 plsql oracle10g

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”时,它期望“loop”立即跟随。我的循环中的代码有很多行,我不想维护它的 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;

关于plsql - oracle 10g pl/sql 条件for循环选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13388450/

相关文章:

sql - Oracle 11 中由函数引起的表变化

date - apache-nifi 纪元日期转换失败

.net - 使用 Microsoft ODBC for Oracle 连接到 Oracle 10g 数据库

mysql - 将 Oracle PL/SQL 转换为 Mysql

sql - 在 oracle 中划分日期范围

sql - 如何在plsql函数中调用函数

compiler-errors - 缺少括号错误Oracle ORA-00907

sql - ORA-06502 : PL/SQL: numeric or value error: character string buffer too small

string - 部分比较两个 varchar2

sql - 如何批量删除Oracle表中大量数据