【发布时间】:2012-08-15 09:22:58
【问题描述】:
我想根据从初始选择语句返回的值执行一系列选择语句。本质上循环遍历原始值并使用该值作为新选择的标准。
我正在尝试做的一些伪代码(我将如何在 shell 中编写它...):
for location in `select places from tablename where XYZ`
do
select new_field from tablename where location = '$location';
done
这是我真正想要运行的选择。
给我一份机架清单:
select regexp_substr("MYTABLE"."Serial_Number" ,'[^ ]+', 1, 3) as "Racks"
from "MYTABLE" "MYTABLE"
where "MYTABLE"."Data_Center" ='SOMEPLACE'
and "MYTABLE"."Device_Type" ='RACK'
and "MYTABLE"."Serial_Number" not like '%WAREHOUSE%'
根据设备数量打印谁应该拥有机架:
select count(*) as count, LOB
from "MYTABLE" "MYTABLE"
where "MYTABLE"."Data_Center" ='SOMEPLACE'
and GRID_LOCATION = '$RACK_from_above' and rownum <= 1 group by LOB order by count desc;
提前致谢!
【问题讨论】:
标签: sql oracle select loops for-loop