如何在oracle

时间:2017-10-19 08:05:32

标签: sql oracle hierarchical-data

我在数据库中按层次顺序存储了类别和分组。每个类别可能有其他类别和分组作为其子女。因此,每当我将分组移动到另一个类别或分组下时,它的类别ID将会更新,并且所有它的分组ID类别ID也应该更新。

GROUPING表的数据如下:

enter image description here

因此,如果我将ID 81分组移动到新类别ID 739720,那么我希望所有儿童分组的类别ID也更新为739720。

换句话说,我想在分层数据结构中选择分组的所有子记录并更新其类别ID。

我希望在UPDATE之后数据如下所示。

enter image description here

1 个答案:

答案 0 :(得分:1)

您可以使用<?php include_once('dbconnect.php'); $sqlPAQuery = "SELECT pages.pageId, pages.pageTitle FROM pages order by pages.pageId"; $paqueryResult = mysqli_query($conn,$sqlPAQuery); echo "<form action = 'delete.php' method = 'post'>"; while ($paqueryRow = mysqli_fetch_assoc($paqueryResult)) { echo "<input type = 'radio' name = '$paqueryRow[pageId]'>".$paqueryRow['pageTitle']."&nbsp"; echo "<input name='Submit' type='submit' value='delete record' /><br/>"; // FIND ALL ARTICLES FOR THIS PAGE $sqlARTICLEQuery = "SELECT * FROM articles where pageId=$paqueryRow[pageId] order by articleId"; $articlequeryResult = mysqli_query($conn,$sqlARTICLEQuery); while ($articlequeryRow = mysqli_fetch_assoc($articlequeryResult)) { echo "<input type = 'radio' name = '$articlequeryRow[articleId]' method = 'post'>".$articlequeryRow['articleTitle']."&nbsp"; echo "<input name='Submit' type='submit' value='delete record' /><br/>"; // VIDEOS FOR EACH ARTICLE $sqlVIDEOQuery = "SELECT * FROM videos where articleId=$articlequeryRow[articleId] order by videoId"; $videoqueryResult = mysqli_query($conn,$sqlVIDEOQuery); while ($videoqueryRow = mysqli_fetch_assoc($videoqueryResult)) { echo "<input type = 'radio' name = '$videoqueryRow[videoId]' method = 'post'>" . $videoqueryRow['videoTitle'] . "&nbsp";// . $videoqueryRow['videoLoc']."&nbsp"; echo "<input name='Submit' type='submit' value='delete record' /><br/>"; //echo"</br>"; } // IMAGE FOR EACH ARTICLE $sqlIMAGEQuery = "SELECT * FROM images where articleId=$articlequeryRow[articleId] order by imageId"; $imagequeryResult = mysqli_query($conn,$sqlIMAGEQuery); while ($imagequeryRow = mysqli_fetch_assoc($imagequeryResult)) { echo "<input type = 'radio' name = '$imagequeryRow[imageId]' method = 'post'>".$imagequeryRow['imageTitle'] . "&nbsp"; //" . $imagequeryRow['imageLoc']."&nbsp"; echo "<input name='Submit' type='submit' value='delete record' /><br/>"; //echo"</br>"; } *// TEXT FOR EACH ARTICLE $sqlTEXTQuery = "SELECT * FROM text where articleId=$articlequeryRow[articleId] order by textId"; $textqueryResult = mysqli_query($conn,$sqlTEXTQuery); while ($textqueryRow = mysqli_fetch_assoc($textqueryResult)) { echo "<input type = 'radio' name = '$textqueryRow[textId]' method = 'post'>".$textqueryRow['textTitle']."&nbsp"; echo "<input name='Submit' type='submit' value='delete record' /><br/>"; if (isset($_POST['textDeleteQuery'])){ $name = $_POST[$textqueryRow['textId']]; $textDeleteQuery = "DELETE FROM text where articleId=$articlequeryRow[articleId] AND textId = ".$_POST[textDeleteQuery['textId']].""; if(mysqli_query($conn, $textDeleteQuery)){ echo "Record deleted successfully"; } else { echo "Error deleting record: " . $conn->error; } } }* echo "<br/>"; } echo "<br/>"; } echo "</form>"; $conn->close(); ?> 声明:

MERGE