A Redefining a SODA Collection
You can use online redefinition to change the metadata or
other properties of an existing collection. In particular, after upgrading so that database
initialization parameter compatible
is at least 20
, you
can migrate a collection to reflect the new default metadata.
The default collection metadata for a database with
compatible
initialization parameter at least
20
has "JSON"
as the value of metadata field
contentColumn.sqlType
. And it has "UUID"
as
the value of metadata field versionColumn.method
. If your
compatible
setting is 20
or greater then
Oracle recommends that you use online redefinition to change the metadata of an
existing collection so that it uses these values.
Online redefinition for a SODA collection is similar to online
redefinition for a database table. The PL/SQL procedures used (in package
DBMS_SODA
) for a collection are analogous to their counterparts
for a table in package DMBS_REDEFINITION
.
Starting with the collection to be redefined, you apply SODA
online-redefinition procedures, one by one. At each step, you can use subprogram
DBMS_SODA.abort_redef_collection
to abort the migration process
if an error is raised.
As an example, the steps presented here migrate collection
MyCollection
so that its metadata reflects that of the default
metadata for a database with initialization parameter compatible
20
or greater.
The following code creates the initial collection to be migrated, which
uses textual JSON data stored as BLOB
content. The default metadata
for a database with parameter compatible
less than
20
is specified here explicitly, for illustration purposes. In
particular, contentColumn.sqlType
is "BLOB"
, and
versionColumn.method
is "SHA256"
.
v_original_collection := 'MyCollection';
v_original_metadata :=
'{"keyColumn": {"name": "ID",
"sqlType": "VARCHAR2",
"maxLength": 255,
"assignmentMethod": "UUID"},
"contentColumn": {"name": "JSON_DOCUMENT",
"sqlType": "BLOB",
"compress": "NONE",
"cache": true,
"encrypt": "NONE",
"validation": "STANDARD"},
"versionColumn": {"name": "VERSION",
"method": "SHA256"},
"lastModifiedColumn": {"name": "LAST_MODIFIED"},
"creationTimeColumn": {"name": "CREATED_ON"},
"readOnly": false}';
DBMS_SODA.create_collection(v_original_collection,
v_original_metadata);
The steps below change fields contentColumn.sqlType
and
versionColumn.method
. The other metadata fields are left
unchanged, except that fields that no longer apply have been removed:
compress
, cache
, encrypt
, and
validation
. (Those fields do not apply to document content
stored as JSON
data type.)
To perform online redefinition for a collection, you need the following database privileges:
-
Privilege
EXECUTE
for PL/SQL packageDBMS_REDEFINITION
-
System privilege
CREATE MATERIALIZED VIEW
-
System privilege
CREATE TABLE
or, if the collection is backed by a table in a database schema different from the current one,CREATE ANY TABLE
See Also:
Summary of SODA Online Redefinition Subprograms in Oracle Database PL/SQL Packages and Types Reference