Apress.Expert.Oracle.Database.Architecture.9i.and.10g.Programming.Techniques.and.Solutions.Sep.2005

rekharaghuram
from rekharaghuram More from this publisher
05.11.2015 Views

CHAPTER 10 ■ DATABASE TABLES 413 • SYS_NC_OID$: This is the system-generated object ID of the table. It is a unique RAW(16) column. It has a unique constraint on it, and there is a corresponding unique index created on it as well. • SYS_NC_ROWINFO: This is the same “magic” function we observed with the nested table. If we select that from the table, it returns the entire row as a single column: ops$tkyte@ORA10G> select sys_nc_rowinfo$ from people; SYS_NC_ROWINFO$(NAME, DOB, HOME_ADDRESS(CITY,STREET,STATE,ZIP), WORK_ADDRESS ---------------------------------------------------------------------------- PERSON_TYPE('Tom', '15-MAR-65', ADDRESS_TYPE('Reston', '123 Main Street', 'Va', 45678), ADDRESS_TYPE('Redwood', '1 Oracle Way', 'Ca', 23456)) • NAME, DOB: These are the scalar attributes of our object table. They are stored much as we would expect, as regular columns. • HOME_ADDRESS, WORK_ADDRESS: These are “magic” functions as well. They return the collection of columns they represent as a single object. These consume no real space except to signify NULL or NOT NULL for the entity. • SYS_NCnnnnn$: These are the scalar implementations of our embedded object types. Since the PERSON_TYPE had the ADDRESS_TYPE embedded in it, Oracle needed to make room to store them in the appropriate type of columns. The system-generated names are necessary since a column name must be unique, and there is nothing stopping us from using the same object type more than once as we did here. If the names were not generated, we would have ended up with the ZIP column twice. So, just like with the nested table, there is a lot going on here. A pseudo primary key of 16 bytes was added, there are virtual columns, and an index was created for us. We can change the default behavior with regard to the value of the object identifier assigned to an object, as we’ll see in a moment. First, let’s look at the full verbose SQL that would generate our table for us. Again, this was generated using EXP/IMP since I wanted to easily see the dependent objects, including all of the SQL needed to re-create this object. This was achieved via the following: [tkyte@localhost tkyte]$ exp userid=/ tables=people rows=n Export: Release 10.1.0.3.0 - Production on Sun May 1 14:04:16 2005 Copyright (c) 1982, 2004, Oracle. All rights reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.1.0.3.0 - Production With the Partitioning, OLAP and Data Mining options Export done in WE8ISO8859P1 character set and AL16UTF16 NCHAR character set Note: table data (rows) will not be exported About to export specified tables via Conventional Path ... . . exporting table PEOPLE Export terminated successfully without warnings.

414 CHAPTER 10 ■ DATABASE TABLES [tkyte@localhost tkyte]$ imp userid=/ indexfile=people.sql full=y Import: Release 10.1.0.3.0 - Production on Sun May 1 14:04:33 2005 Copyright (c) 1982, 2004, Oracle. All rights reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.1.0.3.0 - Production With the Partitioning, OLAP and Data Mining options Export file created by EXPORT:V10.01.00 via conventional path import done in WE8ISO8859P1 character set and AL16UTF16 NCHAR character set Import terminated successfully without warnings. Review of the people.sql file that results would show this: CREATE TABLE "OPS$TKYTE"."PEOPLE" OF "PERSON_TYPE" OID 'F610318AC3D8981FE030007F01001464' OIDINDEX (PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 131072 NEXT 131072 MINEXTENTS 1 MAXEXTENTS 4096 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "USERS") PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 LOGGING STORAGE(INITIAL 131072 NEXT 131072 MINEXTENTS 1 MAXEXTENTS 4096 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "USERS" NOCOMPRESS / ALTER TABLE "OPS$TKYTE"."PEOPLE" MODIFY ("SYS_NC_OID$" DEFAULT SYS_OP_GUID()) / This gives us a little more insight into what is actually taking place here. We see the OIDINDEX clause clearly now, and we see a reference to the SYS_NC_OID$ column. This is the hidden primary key of the table. The function SYS_OP_GUID is the same as the function SYS_GUID. They both return a globally unique identifier that is a 16-byte RAW field. The OID '' syntax is not documented in the Oracle documentation. All this is doing is ensuring that during an EXP and subsequent IMP, the underlying type PERSON_TYPE is in fact the same type. This will prevent an error that would occur if we performed the following steps: 1. Create the PEOPLE table. 2. Export the table. 3. Drop the table and the underlying PERSON_TYPE. 4. Create a new PERSON_TYPE with different attributes. 5.

414<br />

CHAPTER 10 ■ DATABASE TABLES<br />

[tkyte@localhost tkyte]$ imp userid=/ indexfile=people.sql full=y<br />

Import: Release 10.1.0.3.0 - Production on Sun May 1 14:04:33 2005<br />

Copyright (c) 1982, 2004, <strong>Oracle</strong>. All rights reserved.<br />

Connected to: <strong>Oracle</strong> <strong>Database</strong> 10g Enterprise Edition Release 10.1.0.3.0 - Production<br />

With the Partitioning, OLAP <strong>and</strong> Data Mining options<br />

Export file created by EXPORT:V10.01.00 via conventional path<br />

import done in WE8ISO8859P1 character set <strong>and</strong> AL16UTF16 NCHAR character set<br />

Import terminated successfully without warnings.<br />

Review of the people.sql file that results would show this:<br />

CREATE TABLE "OPS$TKYTE"."PEOPLE"<br />

OF "PERSON_TYPE" OID 'F610318AC3D8981FE030007F01001464'<br />

OIDINDEX (PCTFREE 10 INITRANS 2 MAXTRANS 255<br />

STORAGE(INITIAL 131072 NEXT 131072<br />

MINEXTENTS 1 MAXEXTENTS 4096<br />

PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1<br />

BUFFER_POOL DEFAULT)<br />

TABLESPACE "USERS")<br />

PCTFREE 10 PCTUSED 40<br />

INITRANS 1 MAXTRANS 255<br />

LOGGING STORAGE(INITIAL 131072 NEXT 131072<br />

MINEXTENTS 1 MAXEXTENTS 4096<br />

PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1<br />

BUFFER_POOL DEFAULT) TABLESPACE "USERS" NOCOMPRESS<br />

/<br />

ALTER TABLE "OPS$TKYTE"."PEOPLE" MODIFY<br />

("SYS_NC_OID$" DEFAULT SYS_OP_GUID())<br />

/<br />

This gives us a little more insight into what is actually taking place here. We see the<br />

OIDINDEX clause clearly now, <strong>and</strong> we see a reference to the SYS_NC_OID$ column. This is the hidden<br />

primary key of the table. The function SYS_OP_GUID is the same as the function SYS_GUID.<br />

They both return a globally unique identifier that is a 16-byte RAW field.<br />

The OID '' syntax is not documented in the <strong>Oracle</strong> documentation.<br />

All this is doing is ensuring that during an EXP <strong>and</strong> subsequent IMP, the underlying type<br />

PERSON_TYPE is in fact the same type. This will prevent an error that would occur if we performed<br />

the following steps:<br />

1. Create the PEOPLE table.<br />

2. Export the table.<br />

3. Drop the table <strong>and</strong> the underlying PERSON_TYPE.<br />

4. Create a new PERSON_TYPE with different attributes.<br />

5.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!