完整例程的示例

下列 CREATE FUNCTION 语句创建读取客户地址的例程:
CREATE FUNCTION read_address       (lastname CHAR(15)) -- one argument
          RETURNING CHAR(15), CHAR(15), CHAR(20), CHAR(15),CHAR(2)
          CHAR(5); -- 6 items
          
          DEFINE p_lname,p_fname, p_city CHAR(15); 
          --define each routine variable
          DEFINE p_add CHAR(20);
          DEFINE p_state CHAR(2);
          DEFINE p_zip CHAR(5);
          
          SELECT fname, address1, city, state, zipcode
          INTO p_fname, p_add, p_city, p_state, p_zip
          FROM customer
          WHERE lname = lastname;
          
          RETURN p_fname, lastname, p_add, p_city, p_state, p_zip;
          --6 items
          END FUNCTION;
          
          DOCUMENT 'This routine takes the last name of a customer as', 
          --brief description
          'its only argument. It returns the full name and address',
          'of the customer.'
          
          WITH LISTING IN 'pathname' -- modify this pathname according
          -- to the conventions that your operating system requires 
          
          -- compile-time warnings go here
          ; -- end of the routine read_address