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 ein Schauspieler mitgespielt hat, dessen Name "Kramer" beinhaltet.

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[contains(., "Kramer")]');

    Output:

    Id Title Year
    Comrades of Summer, The (1992) (TV) Comrades of Summer, The 1992
    Edge of Night, The Edge of Night, The 1984
    I Was a Communist for the FBI (1951) I Was a Communist for the FBI 1951
  • URL:
  • Language: Deutsch
  • Subjects: Databases
  • Type: Name
  • Duration: 20min
  • Credits: 2
  • Difficulty: 0.4
  • Tags: sql xml xquery xpath
  • Note:
    HPI, 2015-07-13, Datenbanksysteme 1, Aufgabe 5.4b
  • Created By: adius
  • Created At:
    2015-07-27 15:14:55 UTC
  • Last Modified:
    2015-07-27 15:14:55 UTC