Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

414 Chapter 19: Object-Relational Support retrieve just the value of a single column, we use "dot" nota- tion. The first portion-- DEREF(related_ingredient) --actually performs the dereference. The portion to the right of the dot specifies the column in the referenced row. Some DBMSs provide a dereference operator (->) that can be used in place of the DEREF function. The preceding query might be written: SELECT related_ingredient->ingredient_name, amount FROM ingredient_amount; Methods The UDTs that we have seen to this point have attributes, but not methods. It is certainly possible, however, to declare meth- ods as part of a UDT and then to use SQL programming to define the body of the methods. Like classes used by OO pro- gramming languages such C++, SQL the body a method is defined separately from the declaration of the UDT. You declare a method after declaring the structure of a UDT. For example, we could add a method to display the instruc- tions of a recipe with CREATE TYPE recipe_type AS OBJECT (recipe_name CHAR (256), instruction_list instruction ARRAY[20], numb_servings INT) NOT INSTANTIABLE, NOT FINAL METHOD show_instructions (); This particular method does not return a value and the dec- laration therefore does not include the optional RETURNS clause. However, a method to compute the cost of a recipe (if we were to include ingredient costs in the database) could be declared as