An ANYDATA TYPE contains an instance of a given type and the description of the type. ANYDATA is self-describing.
Notice
ANYDATAis currently supported only in PL, but cannot be used as a table column nor persistently stored in the database.- Persistent storage of
ANYDATAinstances whose type contains embedded LOBs is currently not supported.
Applicability
This topic applies only to OceanBase Database Enterprise Edition. OceanBase Database Community Edition provides only the MySQL mode.
Construction
There are two ways to construct an ANYDATA:
Construct an
ANYDATAin its entirety through a single call toCONVERT *.STATIC FUNCTION ConvertNumber(num IN NUMBER) return AnyData, STATIC FUNCTION ConvertDate(dat IN DATE) return AnyData, STATIC FUNCTION ConvertChar(c IN CHAR) return AnyData, STATIC FUNCTION ConvertVarchar(c IN VARCHAR) return AnyData, STATIC FUNCTION ConvertVarchar2(c IN VARCHAR2) return AnyData, STATIC FUNCTION ConvertRaw(r IN RAW) return AnyData, STATIC FUNCTION ConvertBlob(b IN BLOB) return AnyData, STATIC FUNCTION ConvertClob(c IN CLOB) return AnyData, STATIC FUNCTION ConvertObject(obj IN "<ADT_1>") return AnyData, STATIC FUNCTION ConvertCollection(col IN "<COLLECTION_1>") return AnyData, /* Convert calls to Datetime and Nchar types. */ STATIC FUNCTION ConvertTimestamp(ts IN TIMESTAMP_UNCONSTRAINED) return AnyData, STATIC FUNCTION ConvertTimestampTZ(ts IN TIMESTAMP_TZ_UNCONSTRAINED) return AnyData, STATIC FUNCTION ConvertTimestampLTZ(ts IN TIMESTAMP_LTZ_UNCONSTRAINED) return AnyData, STATIC FUNCTION ConvertIntervalYM(inv IN YMINTERVAL_UNCONSTRAINED) return AnyData, STATIC FUNCTION ConvertIntervalDS(inv IN DSINTERVAL_UNCONSTRAINED) return AnyData, STATIC FUNCTION ConvertNchar(nc IN NCHAR) return AnyData, STATIC FUNCTION ConvertNVarchar2(nc IN NVARCHAR2) return AnyData, /* Convert calls to BFloat, BDouble, and URowid types. */ STATIC FUNCTION ConvertBFloat(fl IN BINARY_FLOAT) return AnyData, STATIC FUNCTION ConvertBDouble(dbl IN BINARY_DOUBLE) return AnyData, STATIC FUNCTION ConvertURowid(rid IN UROWID) return AnyData,Construct an
ANYDATAby using a piece-by-piece approach.A call to the
BEGINCREATEstatic procedure begins the construction process and a call to theENDCREATEmember procedure finishes the construction process. Between these two calls, you can useSET*calls to set the individual attributes of an object type or the elements of a collection. For piece-by-piece access to the attributes of objects and elements of a collection, thePIECEWISEmember procedure should be called prior toGET*member functions.Notice
The
ANYDATAmust be constructed or accessed sequentially starting from its first attribute (or collection element). TheBEGINCREATEcall automatically begins the construction in a piece-by-piece manner.PIECEWISEdoes not need to be called immediately afterBEGINCREATEis called.ENDCREATEshould 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 in case of type mismatch. Instead, if the type of the ANYDATA does not match the type of access, these functions return NULL. If you want to use only ANYDATA functions of the appropriate types returned in a query, you should use a WHERE clause that contains GETTYPENAME and select the type you are interested in, such as SYS.NUMBER. Each of these functions returns a value of the specified data type in a SYS.ANYDATA wrapper.
MEMBER FUNCTION AccessNumber(self IN AnyData) return NUMBER DETERMINISTIC,
MEMBER FUNCTION AccessDate(self IN AnyData) return DATE DETERMINISTIC,
MEMBER FUNCTION AccessChar(self IN AnyData) return CHAR DETERMINISTIC,
MEMBER FUNCTION AccessVarchar(self IN AnyData) return VARCHAR DETERMINISTIC,
MEMBER FUNCTION AccessVarchar2(self IN AnyData) return VARCHAR2 DETERMINISTIC,
MEMBER FUNCTION AccessRaw(self IN AnyData) return RAW DETERMINISTIC,
MEMBER FUNCTION AccessBlob(self IN AnyData) return BLOB DETERMINISTIC,
MEMBER FUNCTION AccessClob(self IN AnyData) return CLOB DETERMINISTIC,
MEMBER FUNCTION AccessTimestamp(self IN AnyData) return TIMESTAMP_UNCONSTRAINED DETERMINISTIC,
MEMBER FUNCTION AccessTimestampTZ(self IN AnyData) return TIMESTAMP_TZ_UNCONSTRAINED DETERMINISTIC,
MEMBER FUNCTION AccessTimestampLTZ(self IN AnyData) return TIMESTAMP_LTZ_UNCONSTRAINED DETERMINISTIC,
MEMBER FUNCTION AccessIntervalYM(self IN AnyData) return YMINTERVAL_UNCONSTRAINED DETERMINISTIC,
MEMBER FUNCTION AccessIntervalDS(self IN AnyData) return DSINTERVAL_UNCONSTRAINED DETERMINISTIC,
MEMBER FUNCTION AccessNchar(self IN AnyData) return NCHAR DETERMINISTIC,
MEMBER FUNCTION AccessNVarchar2(self IN AnyData) return NVARCHAR2 DETERMINISTIC,
/* Access calls to Float, Double, and Rowid */
MEMBER FUNCTION AccessBFloat(self IN AnyData) return BINARY_FLOAT DETERMINISTIC,
MEMBER FUNCTION AccessBDouble(self IN AnyData) return BINARY_DOUBLE DETERMINISTIC,
MEMBER FUNCTION AccessURowid(self IN AnyData) return UROWID DETERMINISTIC;
Subprograms
The following table describes the ANYDATA subprograms supported by the current OceanBase Database version.
| Subprogram | Description |
|---|---|
| BEGINCREATE static procedure | Begins the process of creating an ANYDATA. |
| ENDCREATE member procedure | Ends the process of creating an ANYDATA. |
| GET* member functions | Gets the current data value of the appropriate type. |
| GETTYPE member function | Gets the type of the ANYDATA. |
| GETTYPENAME member function | Gets the fully qualified type name for the ANYDATA. |
| PIECEWISE member procedure | Sets the mode of access to the current data value as an attribute at a time (if the data value is of TYPECODE_OBJECT). |
| SET* member procedures | Sets the current data value. |