sql - Oracle SQL 按级别连接

标签 sql oracle

任何人都可以解释以下查询的行为:-

select level,t.*
from 
( select 'one','two'from dual
  union all
  select 'one','two'from dual
) t
connect by level<=2

内部查询中有 2 行。我期待 4 行输出,但我得到 6 行输出。为什么会这样,这是如何工作的?

最佳答案

查询从您的两行之一开始并添加两行,然后继续第二行并再次添加两行。

像这样更改您的查询:

select level,t.*
from 
( select 'one' from dual
  union all
  select 'two' from dual
) t
connect by level<=2;

这使得更容易看到发生了什么:
1   one
2   one
2   two
1   two
2   one
2   two

关于sql - Oracle SQL 按级别连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23992080/

相关文章:

mysql - sql - 排除空值

php - 查询执行时间非常长

sql统计io扫描计数说明

sql-server - Oracle 删除约束级联等效于 Sql Server

mysql - 在 SQL 中出现错误 "No matching Unique or Primary key for the Column List"

oracle - 使用完整的 tnsname 与负载平衡主机、jdbc 连接到数据库

java - 如何在 Oracle UCP 中使用 TimeToLiveConnectionTimeoutCallback

SQL 服务器 : stored procedure using recursive CTE finding values matching a total

sql - 将元组值转换为列名

java - Hibernate关联表映射