The ANYDATA type stores 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. You cannot use it as a column of a table or store it 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 MySQL-compatible mode.
Syntax
You can construct ANYDATA using the following methods:
Build
ANYDATAby callingCONVERT *once.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 the 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, /* Conversion of BFloat, BDouble, and URowid call */ 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 the
ANYDATAby using the piecewise method.The
BEGINCREATEstored procedure is used to initiate the object creation process, while theENDCREATEstored procedure is used to complete the object creation process. During these two calls, use theSET*stored procedures to set the properties or collection elements of an object type. To access object and element attributes in a segmented manner, call thePIECEWISEstored procedure before using theGET*stored procedures.Notice
ANYDATAmust perform an ordered build or access starting with its first attribute (or collection element). ABEGINCREATEcall automatically starts a step-by-step build. A call toPIECEWISEis not required immediately after aBEGINCREATEcall. A call toENDCREATEis required to complete the build process (any access call can be made before this call).
Access methods
You can use SQL statements to access data of any type. These functions do not raise exceptions when the types do not match. Instead, if the type of ANYDATA does not match the type of the data to be accessed, the function returns NULL. To use the ANYDATA function that returns data of the appropriate type in a query, you must specify the WHERE clause, which uses GETTYPENAME to select the type of interest, such as SYS.NUMBER. Each function returns a value of the specified data type 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 describes the ANYDATA subprograms supported in the current version of OceanBase Database.
| 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 | Gets the current data value, which must be of the appropriate type. |
| GETTYPE member function | Gets the type of ANYDATA. |
| GETTYPENAME member function | Gets the fully qualified type name of ANYDATA. |
| PIECEWISE member stored procedure | Sets the access mode of the current data value to one attribute (if the data value is of the TYPECODE_OBJECT type). |
| SET* member stored procedure | Sets the current data value. |