在Oracle数据库中,"WITH"子句通常用于编写递归查询或者子查询,并且可以在查询中创建临时的命名结果集。这样可以使得复杂的查询变得更加清晰和易于理解。WITH子句也被称为公共表表达式(CTE)。
下面是一个简单的示例,演示了WITH子句的基本用法:
with
t1 as (select hostid,host,status from hosts where flags<3),
t2 as (select hostid,ip from interface),
t3 as (select t1.hostid,t1.host,t2.ip from t2,t1 where t1.hostid=t2.hostid)
select * from t3;