background image
<< Triggered-SQL-statement | CREATE VIEW statement >>

The CREATE TYPE statement

<< Triggered-SQL-statement | CREATE VIEW statement >>
Derby Reference Manual
48
·
CURRENT_TIME function
·
CURRENT_TIMESTAMP function
·
CURRENT_USER function
·
SESSION_USER function
·
USER function
ReferencingClause:
REFERENCING
{
{ OLD | NEW } [ ROW ] [ AS ] correlation-Name [ { OLD | NEW } [ ROW ] [
AS ] correlation-Name ] |
{ OLD TABLE | NEW TABLE } [ AS ] Identifier [ { OLD TABLE | NEW TABLE }
[AS] Identifier ] |
{ OLD_TABLE | NEW_TABLE } [ AS ] Identifier [ { OLD_TABLE | NEW_TABLE }
[AS] Identifier ]
}
Note: The
OLD_TABLE | NEW_TABLE
syntax is deprecated since it is not SQL
compliant and is intended for backward compatibility and DB2 compatibility.
CREATE TYPE statement
The CREATE TYPE statement creates a user-defined type (UDT). A UDT is a
serializable Java class whose instances are stored in columns. The class must
implement the java.io.Serializable interface.
Syntax
CREATE TYPE [
schemaName
. ]
SQL92Identifier
EXTERNAL NAME singleQuotedJavaClassName
LANGUAGE JAVA
The type name is composed of an optional schemaName and a SQL92Identifier. If a
schemaName is not provided, the current schema is the default schema. If a qualified
type name is specified, the schema name cannot begin with SYS.
If the Java class does not implement java.io.Serializable, or if it is not public and visible
on the classpath, Derby raises an exception when preparing statements which refer to
the UDT.
A UDT cannot be cast explicitly to any other type, and no other type can be cast to a
UDT.
A UDT has no ordering. This means that you cannot compare and sort UDTs. You cannot
use them in expressions involving the
<
,
=
,
>
, IN, BETWEEN, and LIKE operators. You
cannot use UDTs in aggregates, DISTINCT expressions, and GROUP/ORDER BY
clauses. You cannot build indexes on them.
You can use subtypes in UDTs. That is, if you use the CREATE TYPE statement to bind
a class named C to a UDT, you can populate that UDT value with an instance of any
subclass of C.
Example
CREATE TYPE price
EXTERNAL NAME 'com.example.types.Price'
LANGUAGE JAVA
Using user-defined types
You can create tables and views with columns that have UDTs. For example:
CREATE TABLE order
(
orderID INT GENERATED ALWAYS AS IDENTITY,