Using ANYDATA TYPE

Restrictions

Operational Notes

Construction

There are 2 ways to construct an ANYDATA. The CONVERT* calls enable construction of the ANYDATA in its entirety with a single call. They serve as explicit CAST functions from any type in the Oracle ORDBMS to ANYDATA.

The second way to construct an ANYDATA is a piece by piece approach. The BEGINCREATE Static Procedure call begins the construction process and ENDCREATE Member Procedure call finishes the construction process. In between these two calls, the individual attributes of an object type or the elements of a collection can be set using SET* calls. For piece by piece access of the attributes of objects and elements of collections, the PIECEWISE Member Procedure should be invoked prior to GET* calls.

Note: The ANYDATA has to be constructed or accessed sequentially starting from its first attribute (or collection element). The BEGINCREATE call automatically begins the construction in a piece-wise mode. There is no need to call PIECEWISE immediately after BEGINCREATE. ENDCREATE should be called to finish the construction process (before which any access calls can be made).

Access

Access functions are available based on SQL. These functions do not throw exceptions on type-mismatch. Instead, they return NULL if the type of the ANYDATA does not correspond to the type of access. If you wish to use only ANYDATA functions of the appropriate types returned in a query, you should use a WHERE clause which uses GETTYPENAME and choose the type you are interested in (say "SYS.NUMBER"). Each of these functions returns the value of a specified datatype inside a SYS.ANYDATA wrapper.

MEMBER FUNCTION AccessBDouble(self IN ANYDATA) return BINARY_DOUBLE
DETERMINISTIC,
MEMBER FUNCTION AccessBfile(self IN ANYDATA) return BFILE,
MEMBER FUNCTION AccessBFloat(self IN ANYDATA) return BINARY_FLOAT
DETERMINISTIC,
MEMBER FUNCTION AccessBlob(self IN ANYDATA) return BLOB,
MEMBER FUNCTION AccessChar(self IN ANYDATA) return CHAR,
MEMBER FUNCTION AccessClob(self IN ANYDATA) return CLOB,
MEMBER FUNCTION AccessDate(self IN ANYDATA) return DATE,
MEMBER FUNCTION AccessIntervalYM(self IN ANYDATA) return INTERVAL YEAR TO MONTH,
MEMBER FUNCTION AccessIntervalDS(self IN ANYDATA) return INTERVAL DAY TO SECOND,
MEMBER FUNCTION AccessNchar(self IN ANYDATA) return NCHAR,
MEMBER FUNCTION AccessNClob(self IN ANYDATA) return NCLOB
MEMBER FUNCTION AccessNumber(self IN ANYDATA) return NUMBER,
MEMBER FUNCTION AccessNVarchar2(self IN ANYDATA) return NVARCHAR2,
MEMBER FUNCTION AccessRaw(self IN ANYDATA) return RAW,
MEMBER FUNCTION AccessTimestamp(self IN ANYDATA) return TIMESTAMP,
MEMBER FUNCTION AccessTimestampLTZ(self IN ANYDATA) return TIMESTAMP WITH LOCAL
TIMEZONE,
MEMBER FUNCTION AccessTimestampTZ(self IN ANYDATA) return TIMESTAMP WITH
TIMEZONE,
MEMBER FUNCTION AccessURowid(self IN ANYDATA) return UROWID DETERMINISTIC
MEMBER FUNCTION AccessVarchar(self IN ANYDATA) return VARCHAR,
MEMBER FUNCTION AccessVarchar2(self IN ANYDATA) return VARCHAR2,

The AnyType corresponding to the ANYDATA. May be NULL if it does not represent a user-defined type.

Return Values

The typecode corresponding to the type of the ANYDATA.

GETTYPENAME Member Function

This function gets the fully qualified type name for the ANYDATA.

If the ANYDATA is based on a built-in type, this function will return NUMBER and other relevant information.

If it is based on a user defined type, this function will return schema_name.type_name, for example, SCOTT.FOO.

If it is based on a transient anonymous type, this function will return NULL.

Syntax

MEMBER FUNCTION GETTYPENAME(
self IN ANYDATA)
RETURN VARCHAR2;

Parameters

Table 241-6 GETTYPENAME Function Parameter

Parameter

Description

self

An ANYDATA.

Return Values

Type name of the ANYDATA.

PIECEWISE Member Procedure

This procedure sets the MODE of access of the current data value to be an attribute at a time (if the data value is of TYPECODE_OBJECT).

It sets the MODE of access of the data value to be a collection element at a time (if the data value is of collection type). Once this call has been made, subsequent calls to SET* and GET* will sequentially obtain individual attributes or collection elements.

Syntax

MEMBER PROCEDURE PIECEWISE(
self IN OUT NOCOPY ANYDATA);

Parameters

Table 241-7 PIECEWISE Procedure Parameters

Parameter

Description

self

The current data value.

Exceptions

DBMS_TYPES.INVALID_PARAMETERS

DBMS_TYPES.INCORRECT_USAGE: On incorrect usage.

Usage Notes

The current data value must be of an OBJECT or COLLECTION type before this call can be made.

Piece-wise construction and access of nested attributes that are of object or collection types is not supported.

SET* Member Procedures

Sets the current data value.

This is a list of procedures that should be called depending on the type of the current data value. The type of the data value should be the type of the attribute at the current position during the piece-wise construction process.

Syntax

MEMBER PROCEDURE SETBDOUBLE(
self IN OUT NOCOPY ANYDATA,
dbl IN BINARY_DOUBLE,
last_elem IN boolean DEFAULT FALSE);
MEMBER PROCEDURE SETBFILE(
self IN OUT NOCOPY ANYDATA,
b IN BFILE,
last_elem IN boolean DEFAULT FALSE);
MEMBER PROCEDURE SETBFLOAT(
self IN OUT NOCOPY ANYDATA,
fl IN BINARY_FLOAT,
last_elem IN boolean DEFAULT FALSE);
MEMBER PROCEDURE SETBLOB(
self IN OUT NOCOPY ANYDATA,
b IN BLOB,
last_elem IN boolean DEFAULT FALSE);
MEMBER PROCEDURE SETCHAR(
self IN OUT NOCOPY ANYDATA,
c IN CHAR,
last_elem IN boolean DEFAULT FALSE);
MEMBER PROCEDURE SETCLOB(
self IN OUT NOCOPY ANYDATA,
c IN CLOB,
last_elem IN boolean DEFAULT FALSE);
MEMBER PROCEDURE SETCOLLECTION(
self IN OUT NOCOPY ANYDATA,
col IN "<collectyion_type>",
last_elem IN boolean DEFAULT FALSE);
MEMBER PROCEDURE SETDATE(
self IN OUT NOCOPY ANYDATA,
dat IN DATE,
last_elem IN boolean DEFAULT FALSE);
MEMBER PROCEDURE SETINTERVALDS(
self IN OUT NOCOPY ANYDATA,
inv IN INTERVAL DAY TO SECOND,
last_elem IN boolean DEFAULT FALSE);
MEMBER PROCEDURE SETINTERVALYM(
self IN OUT NOCOPY ANYDATA,
inv IN INTERVAL YEAR TO MONTH,
last_elem IN boolean DEFAULT FALSE);
MEMBER PROCEDURE SETNCHAR(
self IN OUT NOCOPY ANYDATA,
nc IN NCHAR,
last_elem IN boolean DEFAULT FALSE);
MEMBER PROCEDURE SETNCLOB(
self IN OUT NOCOPY ANYDATA,
nc IN NClob,
last_elem IN boolean DEFAULT FALSE);
MEMBER PROCEDURE SETNUMBER(
self IN OUT NOCOPY ANYDATA,
num IN NUMBER,
last_elem IN boolean DEFAULT FALSE);
MEMBER PROCEDURE SETNVARCHAR2(
self IN OUT NOCOPY ANYDATA,
nc IN NVarchar2,
last_elem IN boolean DEFAULT FALSE),
MEMBER PROCEDURE SETOBJECT(
self IN OUT NOCOPY ANYDATA,
obj IN "<object_type>",
last_elem IN boolean DEFAULT FALSE);
MEMBER PROCEDURE SETRAW(
self IN OUT NOCOPY ANYDATA,
r IN RAW,
last_elem IN boolean DEFAULT FALSE);
MEMBER PROCEDURE SETREF(
self IN OUT NOCOPY ANYDATA,
rf IN REF "<object_type>",
last_elem IN boolean DEFAULT FALSE);
MEMBER PROCEDURE SETTIMESTAMP(
self IN OUT NOCOPY ANYDATA,
ts IN TIMESTAMP,
last_elem IN BOOLEAN DEFAULT FALSE);
MEMBER PROCEDURE SETTIMESTAMPTZ(self IN OUT NOCOPY ANYDATA,
ts IN TIMESTAMP WITH TIME ZONE,
last_elem IN BOOLEAN DEFAULT FALSE);
MEMBER PROCEDURE SETTIMESTAMPLTZ(
self IN OUT NOCOPY ANYDATA,
ts IN TIMESTAMP WITH LOCAL TIME ZONE,
last_elem IN boolean DEFAULT FALSE),
MEMBER PROCEDURE SETVARCHAR(
self IN OUT NOCOPY ANYDATA,
c IN VARCHAR,
last_elem IN boolean DEFAULT FALSE);
MEMBER PROCEDURE SETVARCHAR2(
self IN OUT NOCOPY ANYDATA,
c IN VARCHAR2,
last_elem IN boolean DEFAULT FALSE);

Parameters

Table 241-8 SET* Procedure Parameters

Parameter

Description

self

An ANYDATA.

num

The number, and associated information, that is to be set.

last_elem

Relevant only if ANYDATA represents a collection.

Set to TRUE if it is the last element of the collection, FALSE otherwise.

Exceptions

DBMS_TYPES.INVALID_PARAMETERS: Invalid Parameters (if it is not appropriate to add a number at this point in the creation process).

DBMS_TYPES.INCORRECT_USAGE: Incorrect usage.

DBMS_TYPES.TYPE_MISMATCH: When the expected type is different from the passed in type.

Usage Notes

When BEGINCREATE is called, construction has already begun in a piece-wise fashion. Subsequent calls to SET* will set the successive attribute values.

If the ANYDATA is a standalone collection, the SET* call will set the successive collection elements.

Scripting on this page enhances content navigation, but does not change the content in any way.