The ANYDATA type contains an instance of a specified type and a description of the type. ANYDATA is self-descriptive.
Notice
- Currently, you can use the
ANYDATAtype only in PL/SQL. It cannot be used as a column of a table or stored permanently. - Currently, you cannot store instances of the
ANYDATAtype that contain embeddedLOBdata permanently.
Applicability
This topic applies only to OceanBase Database Enterprise Edition. OceanBase Database Community Edition provides only the MySQL mode.
Construction methods
There are two methods for constructing ANYDATA:
Use a single call to
CONVERT *to constructANYDATA.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, /* Calls for converting 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, /* Calls for converting BFloat, BDouble, and URowid */ 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,Use the piecewise method to construct
ANYDATA.The construction process starts with a call to the
BEGINCREATEstatic stored procedure and ends with a call to theENDCREATEmember stored procedure. Between these two calls, you can useSET*calls to set individual attributes of an object type or elements of a collection. To access the elements of a collection or the attributes of an object in a piecewise manner, you must call thePIECEWISEmember stored procedure before usingGET*calls.Notice
ANYDATAmust be constructed or accessed sequentially, starting with its first attribute (or collection element). TheBEGINCREATEcall automatically starts the piecewise construction. You do not need to immediately callPIECEWISEafterBEGINCREATE. You should callENDCREATEto complete the construction process (any access calls can be made before this).
Access methods
You can use SQL statements to access the ANYDATA type. These functions do not raise exceptions when the types do not match. Instead, they return NULL if the type of ANYDATA does not match the type of the data to be accessed. If you want to use only the ANYDATA functions that return the appropriate types in queries, you can use the WHERE clause with GETTYPENAME to filter for the desired type, such as SYS.NUMBER. Each function returns a value of the specified data type wrapped in the 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,
/* Float, Double, and Rowid access calls*/
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;
Overview of ANYDATA subprograms
The following table lists the ANYDATA subprograms supported in the current version of OceanBase Database and provides a brief description of each.
| Subprogram | Description |
|---|---|
| BEGINCREATE static stored procedure | Starts the creation of a new ANYDATA object. |
| ENDCREATE member stored procedure | Ends the creation of an ANYDATA object. |
| GET* member function | Retrieves the current data value, which should be of the appropriate type. |
| GETTYPE member function | Retrieves the type of the ANYDATA object. |
| GETTYPENAME member function | Retrieves the fully qualified type name of the ANYDATA object. |
| PIECEWISE member stored procedure | Sets the access mode for the current data value to attribute-by-attribute (if the data value is of type TYPECODE_OBJECT). |
| SET* member stored procedure | Sets the current data value. |