CS145 Assignment #5

Due 2:45PM Thursday, November 18, 2004

Step 5 of Your PDA

As previously, we would like you to use the submit script to hand in your work.
  1. Write three PL/SQL stored functions or procedures (See the PL/SQL Guide) to perform operations on your PDA database. Each should be nontrivial, illustrating a feature or features such as local variables, multiple SQL statements, loops, and branches. In addition, at least one should involve a cursor. We encourage you to be imaginative. However, here are some sorts of things you might try if you can't think of something more interesting:

    a)
    Compute some aggregate value from a relation and use that value to modify values in that or another relation.
    b)
    Create a new relation and load it with values computed from one or more existing relations.
    c)
    Enforce a constraint by searching your database for violations and fixing them in some way.

    Submit two files: functions.sql and functions.log. The first file should contain the PL/SQL that declares your functions and procedures. The second file should contain be a script recording of your sqlplus session showing successful compilation of your function/procedures and the execution of queries that use these functions/procedures successfully. You should also include additional queries that demonstrate the functions/procedures have had their intended effect.

  2. Write two Oracle Triggers. (See The Triggers Guide for a synopsis of Oracle triggers.) You should also check The Guide to Nonstandard Oracle Features for some important restrictions on triggers.

    Submit your triggers in a file triggers.sql and a script triggers.log, showing the triggers declared. Also, the script should show, for each trigger, the effect of two database modifications. One modification should trigger the trigger, and the other not. Show in the script queries that demonstrate that the trigger has an effect in the first case and not in the second.

  3. Declare some data types (UDT's) that could be used with the data of your PDA. (See The Object-Relational Guide for a synopsis of Oracle O-R features.) You need to choose types such that:

    For declarations, don't forget type bodies when there are methods. Also remember that the slash is needed to cause compilation.

    Submit two files: datatypes.sql and datatypes.log. The first file should contain SQL statements declaring different data types. The second file should contain a recording of your sqlplus session showing successful execution of your SQL statements.

  4. Declare some relations that could hold data associated with your PDA. Choose relations so that:

    Note that it is possible for one relation to satisfy all these conditions, but it is up to you how many new relations you choose to create. Write INSERT statements to populate your new relations from the data in the original relations of your PDA.

    Submit two files: relations.sql and relations.log. The first file should contain SQL statements to create and to populate relations. The second file should contain a recording of your sqlplus session showing successful compilation of your declarations and correct execution of your insertion statements.

  5. Write some queries on your relations from (4). Among these queries, you should demonstrate the following features at least once:

    Note: Technically, you could write one query to do all of these operations, but we suggest you write a larger number of simpler queries.

    Submit two files: queries.sql and queries.log
    The first file should contain SQL queries over your relations. The second file should contain a recording of your sqlplus session showing successful execution of your queries. Write brief descriptions of SQL statements as comments in the .sql file.