How to Move USER_SDO_GEOM_METADATA like a Grandpa

Sometimes moving a small amount of data in Oracle database requires more work than the actual task you need to complete. DBAs always have their tools (PL/SQL Developer Text Importer is my favorite one) to move a small amount of data between databases.
But when it comes to nested tables this might be a bit challenging. USER_SDO_GEOM_METADATA table (for those of you who are not familiar with it, it is the catalog information of spatial layers in an Oracle database) has no exception to that. Here how it is easy to handle it
The structure of USER_SDO_GEOM_METADATA table has the following structure

SQL> desc user_sdo_geom_metadata
 Name					   Null?    Type
 ----------------------------------------- -------- ----------------------------
 SRID						    NUMBER

Obviously DIMINFO column is the problematic part since it is in SDO_DIM_ARRAY type. Now create a temporary table by unfolding this nested table at the source database site.

CREATE TABLE temp_metadata AS 
  SELECT t.table_name, 
  FROM   user_sdo_geom_metadata t, 
         TABLE(t.diminfo) d; 

Once you are done check the structure of temp_metadata table which only contains primitive SQL types for the columns

SQL> desc temp_metadata
 Name					   Null?    Type
 ----------------------------------------- -------- ----------------------------
 TABLE_NAME					    VARCHAR2(32)
 COLUMN_NAME					    VARCHAR2(1024)
 SDO_LB 					    NUMBER
 SDO_UB 					    NUMBER
 SRID						    NUMBER

Choose your favorite tool to move this table to the target database since it contains just a few rows. Then as the final step import this data into USER_SDO_GEOM_METADATA table at the target database (Ensure that there is no other record with the same table_name.column_name key on the target USER_SDO_GEOM_METADATA table otherwise trigger on it will warn you)

insert into user_sdo_geom_metadata
SELECT m.table_name, m.column_name,
   CAST(MULTISET(SELECT sdo_dimname,sdo_lb,SDO_UB,sdo_tolerance
                 FROM temp_metadata n
                 WHERE n.table_name = m.table_name and n.column_name = m.column_name)
   AS SDO_DIM_ARRAY) as diminfo,
FROM (select distinct table_name,column_name,srid from temp_metadata) m;

You are done! Check everything works fine at the application site.

About kocakahin

Just a computer engineer

Posted on April 27, 2013, in Oracle and tagged , , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: