05.11.2015 Views

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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

416<br />

CHAPTER 10 ■ DATABASE TABLES<br />

ops$tkyte@ORA10G> CREATE TABLE "PEOPLE"<br />

2 OF "PERSON_TYPE"<br />

3 ( constraint people_pk primary key(name) )<br />

4 object identifier is PRIMARY KEY<br />

5 /<br />

Table created.<br />

ops$tkyte@ORA10G> select name, type#, segcollength<br />

2 from sys.col$<br />

3 where obj# = ( select object_id<br />

4 from user_objects<br />

5 where object_name = 'PEOPLE' )<br />

6 <strong>and</strong> name like 'SYS\_NC\_%' escape '\'<br />

7 /<br />

NAME<br />

TYPE# SEGCOLLENGTH<br />

------------------------------ ---------- ------------<br />

SYS_NC_OID$ 23 81<br />

SYS_NC_ROWINFO$ 121 1<br />

According to this, instead of a small 16-byte column, we have a large 81-byte column! In<br />

reality, there is no data stored in there. It will be null. The system will generate a unique ID<br />

based on the object table, its underlying type, <strong>and</strong> the value in the row itself. We can see this<br />

in the following:<br />

ops$tkyte@ORA10G> insert into people (name)<br />

2 values ( 'Hello World!' );<br />

1 row created.<br />

ops$tkyte@ORA10G> select sys_nc_oid$ from people p;<br />

SYS_NC_OID$<br />

-------------------------------------------------------------------------------<br />

F610733A48F865F9E030007F0100149A00000017260100010001002900000000000C07001E01000<br />

02A00078401FE000000140C48656C6C6F20576F726C642100000000000000000000000000000000<br />

0000<br />

ops$tkyte@ORA10G> select utl_raw.cast_to_raw( 'Hello World!' ) data<br />

2 from dual;<br />

DATA<br />

-------------------------------------------------------------------------------<br />

48656C6C6F20576F726C6421<br />

ops$tkyte@ORA10G> select utl_raw.cast_to_varchar2(sys_nc_oid$) data<br />

2 from people;

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

Saved successfully!

Ooh no, something went wrong!