CONNECT BY PRIOR中的“OR”运算符

时间:2017-05-23 04:40:59

标签: sql oracle connect-by

数据库中的行是:

`$amenitiesArray = ['amenityX', 'smoking', 'pets', 'amenityY', 'amenityZ', 'amenityA', 'linens', 'amenityB', 'wifi'] //from api`

 $your_data = ['smoking','pets','linens','wifi'];

echo "<table boder='1px'>";
echo "<thead>";
echo "<tr><th>column1</th><th>colum2</th></tr>";
echo "</thead>";
echo "<tbody>";
foreach($your_data as $row)
{

    echo "<tr><td>".$row."</td>";

    if(in_array($row,$amenitiesArray))
     {
           echo "<td>green icon html</td>";
      }
      else
      {
          echo "<td>red icon html</td>";
      }
      echo "</tr>";
} 

  echo "</tbody>";
  echo "</table>";

我想显示所有这些行,但是通过使用以下查询,只显示前2行,我需要所有3行:

DATAID OWNERID PARENTID
111    123     133
976    346     111
987    976     657

它似乎只运行SELECT * FROM DTREE start with DATAID=111 connect by prior dataid=parentid OR dataid=ownerid; 部分,而不是第二部分。

2 个答案:

答案 0 :(得分:2)

您缺少应用于第二次出现的DATAID的PRIOR运算符:

SELECT * FROM DTREE  start with DATAID=111
connect by prior dataid=parentid OR   prior  /* <-- MISSING!!! */  dataid=ownerid;

可替换地:

connect by prior dataid in (parented, ownerid);

答案 1 :(得分:0)

为防止循环,应使用NOCYCLE子句

SELECT * FROM DTREE  start with DATAID=111
connect by prior nocycle dataid=parentid OR prior dataid=ownerid;