Routines: Methods

Methods allow you to access structured type attributes as well as to define additional behaviors for structured types.

A structured type is a user-defined data type containing one or more named attributes, each of which has a data type. Attributes are properties that describe an instance of a type. A geometric shape, for example, might have attributes such as its list of Cartesian coordinates.

Methods are generally implemented for a structured type to represent operations on the attributes of the structured type. For a geometric shape a method might calculate the volume of the shape. Methods share all of the features of scalar functions.

Features
  • Ability to access structured type attributes
  • Ability to set structured type attributes
  • Ability to create operations on structured type attributes and return a function value
  • Sensitive to the dynamic type of the subject type
Limitations
  • Can only return a scalar value
  • Can only be used with structured types
  • Cannot be invoked for typed tables
Common uses
  • Create operations on structured types
  • Encapsulate the structured type
Supported implementations
There are no built-in methods. Users can create user-defined methods for existing user-defined structured types. Methods can be implemented using one of the following implementations:

SQL methods are easy to implement, but are generally designed in conjunction with the design of a structured type. External methods provide greater support for flexible logic implementation and allow a user to develop method logic in their preferred programming language.