In dieser Aufgabe laden wir die movie-Daten der IMDb im XML-Format in eine Datenbank. Dazu erstellen wir eine Tabelle mit dem Namen moviexml. Jedes Tupel in dieser Tabelle stellt einen Film mit dessen ID (Attribut mid) und weiteren Informationen im XML-Format (Attribut content) dar. Das XML-Attribut eines Film-Tupels hat beispielsweise folgenden Inhalt (hier der Film mit der IDGhosts of the Past (1991) (TV)):

<movie>
    <mid>Ghosts of the Past (1991) (TV)</mid>
    <title>Ghosts of the Past</title>
    <year>1991</year>
    <actors>
        <actor>
            <name>Davis, Carl (IV)</name>
        </actor>
        <actor>
            <name>McCartney, Paul</name>
        </actor>
    </actors>
</movie>

Um die Tabelle zu erzeugen und zu befüllen, gibt es das SQL-Script create_and_insert_utf8.sql. Gib für die folgende Anfrage jeweils sowohl eine geeignete SQL-Anfrage mit eingebetteten XQuery/XPath-Anteilen als auch die Ergebnisse der Anfrage an.

Gib ID, Titel und Jahr aus für alle Filme, in denen der Schauspieler mit dem Namen "Affleck, Ben" mitgespielt hat.

Solution
  • Query:

    select mid as Id,
        xmlquery('$CONTENT/movie/title/text()') as Title,
        xmlquery('$CONTENT/movie/year/text()') as Year
    from moviexml
    where xmlexists('$CONTENT/movie/actors/actor/name[text()="Affleck, Ben"]');

    Output:

    Id Title Year
    Gigli (2003) Gigli 2003
  • URL:
  • Language: Deutsch
  • Subjects: Databases
  • Type: Name
  • Duration: 20min
  • Credits: 2
  • Difficulty: 0.3
  • Tags: sql xml xquery xpath
  • Note:
    HPI, 2015-07-13, Datenbanksysteme 1, Aufgabe 5.4a
  • Created By: adius
  • Created At:
    2015-07-27 15:11:26 UTC
  • Last Modified:
    2015-07-27 15:11:26 UTC