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 and cannot use it as a column in a table or store it permanently. - Currently, you cannot store an instance of the
ANYDATAtype that contains an embeddedLOBpermanently.
Applicability
This topic applies only to OceanBase Database Enterprise Edition. OceanBase Database Community Edition provides only MySQL mode.
Construction methods
There are two methods for constructing ANYDATA:
Use one
CONVERT *call to fully 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 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,Use the piecewise method to construct
ANYDATA.The construction process begins 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 in a piecewise manner, you must call thePIECEWISEmember stored procedure before anyGET*calls.Notice
ANYDATAmust be constructed or accessed in sequence, 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).
Accesses
The functions are available as SQL functions. They do not raise exceptions for type mismatches. Instead, if the type of the ANYDATA value does not match the accessed type, the function returns NULL. If you want to use ANYDATA functions that return values of appropriate types in queries, use the WHERE clause with GETTYPENAME to specify the type you are interested in, such as SYS.NUMBER. Each function returns a value of the specified data type, wrapped in the SYS.ANYDATA type.
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 for 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;
ANYDATA Subprocedures
The following table lists the ANYDATA subprograms available in the current OceanBase Database release and brief descriptions.
| Procedure | Purpose |
|---|---|
| BEGINCREATE static stored procedure | Start creating a new ANYDATA. |
| ENDCREATE | Ends the creation of ANYDATA type. |
| GET* member function | Gets the current data value (must be of the appropriate type). |
| GETTYPE member function | Gets the type of the ANYDATA expression. |
| GETTYPENAME method | Obtains the fully qualified type name of ANYDATA. |
| PIECEWISE member stored procedure | sets the access mode of the current data value to piecewise, if the data value is of the TYPECODE_OBJECT type |
| SET* member stored procedure | Sets the current data value. |