加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Oracle通过join sql-92组合选择星号连接

发布时间:2020-12-12 13:11:38 所属栏目:百科 来源:网络整理
导读:以下查询显示select *与connect by和left join结合不会返回所有列,而只返回在这些条件中使用的列. 这种行为对我很有用,因为select *不应该在发布中使用,它对请求数据很有用. with t1 as ( select 1 id,0 parent,'ROOT' name from dual union all select 2 id
以下查询显示select *与connect by和left join结合不会返回所有列,而只返回在这些条件中使用的列.
这种行为对我很有用,因为select *不应该在发布中使用,它对请求数据很有用.
with t1 as (
  select 1 id,0 parent,'ROOT' name from dual
  union all
  select 2 id,1 parent,'CHILD-1' name from dual
  union all
  select 3 id,'CHILD-2' name from dual
),t2 as (
  select 1 t1id,'node' special from dual
)
  select * from t1
  left join t2 on t2.t1id=t1.id
  start with id = 2
  connect by prior parent = id;

而其他查询返回所有列

select * from t1
  start with id = 2
  connect by prior parent = id;

  select * from t1
  left join t2 on t2.t1id=t1.id;

我找不到关于这个功能的文档,有没有?

我相信您正在寻找的文档可以在这里找到: Hierarchical Queries

最相关的部分:

Oracle processes hierarchical queries as follows:

  • A join,if present,is evaluated first,whether the join is specified in the FROM clause or with WHERE clause predicates.

  • The CONNECT BY condition is evaluated.

  • Any remaining WHERE clause predicates are evaluated.

Oracle then uses the information from these evaluations to form the hierarchy using the following steps:

  1. Oracle selects the root row(s) of the hierarchy–those rows that satisfy the START WITH condition.

  2. Oracle selects the child rows of each root row. Each child row must satisfy the condition of the CONNECT BY condition with respect to one of the root rows.

  3. Oracle selects successive generations of child rows. Oracle first selects the children of the rows returned in step 2,and then the children of those children,and so on. Oracle always selects children by evaluating the CONNECT BY condition with respect to a current parent row.

  4. If the query contains a WHERE clause without a join,then Oracle eliminates all rows from the hierarchy that do not satisfy the condition of the WHERE clause. Oracle evaluates this condition for each row individually,rather than removing all the children of a row that does not satisfy the condition.

  5. Oracle returns the rows in the order shown in Figure 9-1. In the diagram,children appear below their parents. For an explanation of hierarchical trees,see Figure 3-1,“Hierarchical Tree”.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读