Skip to Content
Java Programming with Oracle SQLJ
book

Java Programming with Oracle SQLJ

by Jason Price
August 2001
Intermediate to advanced
400 pages
9h 28m
English
O'Reilly Media, Inc.
Content preview from Java Programming with Oracle SQLJ

4.1. Defining Object Types

In this section, you will learn how to define object types. The examples here create object types that will be used to store the details of a customer and an address. The address type will be embedded within the customer type, enabling a customer's address to be stored as an attribute of the customer. These types form the basis for all the other examples in this chapter.

When defining an object type, you must define a specification. The specification defines the attributes for the object type. If your object type will contain methods, then the signatures for those methods must also be included in the specification. A method signature is made up of the name of the method and any parameters that will be passed to the method. In addition, if your object type contains methods, you must define a body for the type. The body contains the actual code for the methods.

You use the SQL DDL statements CREATE TYPE and CREATE TYPE BODY to create an object type specification and body. The following CREATE TYPE statement defines the specification for an object type named t_address:

CREATE TYPE t_address AS OBJECT (
  street VARCHAR2(15),
  city   VARCHAR2(15),
  state  CHAR(2),
  zip    VARCHAR2(9)
);
/

Because the t_address type will not contain any methods, there's no need to create an object body for the type. A body is necessary only when you need to specify code for a method.

In this chapter's examples, the t_customer object type will be used to store customer details. Unlike ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Java Programming with Oracle JDBC

Java Programming with Oracle JDBC

Donald Bales

Publisher Resources

ISBN: 0596000871Catalog PageErrata