UKOUG 2007 - XMLDB Building Blocks & Best Practices · 10 Brilliant Stuff, This XMLDB Database...

37
1

Transcript of UKOUG 2007 - XMLDB Building Blocks & Best Practices · 10 Brilliant Stuff, This XMLDB Database...

Page 1: UKOUG 2007 - XMLDB Building Blocks & Best Practices · 10 Brilliant Stuff, This XMLDB Database Thingy ! (You only need ONE TABLE !)

��

��

� � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � �

��

��

1

������������������������ �������������

Page 2: UKOUG 2007 - XMLDB Building Blocks & Best Practices · 10 Brilliant Stuff, This XMLDB Database Thingy ! (You only need ONE TABLE !)

��

��

� � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � �

��

��

2

��� �������� � ��������������������

� �������������� ���������������� �������������������

�� !�� ������� ������������ �"�#� �"��� �"��$� ���������

� ��������� ����������%&'� ��($$�����������$�����

����������)����������������������%&'��*� ��+������)��

� ��� ,�������������%&'�-��.*�&�*/��

Page 3: UKOUG 2007 - XMLDB Building Blocks & Best Practices · 10 Brilliant Stuff, This XMLDB Database Thingy ! (You only need ONE TABLE !)

��

��

� � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � �

��

��

3

��������

� ��0���10�2�32���

� %&'��24�&���

� ���0�5����062�60��

� 0�2�1

Page 4: UKOUG 2007 - XMLDB Building Blocks & Best Practices · 10 Brilliant Stuff, This XMLDB Database Thingy ! (You only need ONE TABLE !)

��

��

� � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � �

��

��

4

� ��������������

���� �������� ����������� �����������

Page 5: UKOUG 2007 - XMLDB Building Blocks & Best Practices · 10 Brilliant Stuff, This XMLDB Database Thingy ! (You only need ONE TABLE !)

��

��

� � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � �

��

��

5

&������*���7+��8

9!�����"#���� $�%#�� ���&:

�������������������� �����������������������������������

����������������������������������� ������

Page 6: UKOUG 2007 - XMLDB Building Blocks & Best Practices · 10 Brilliant Stuff, This XMLDB Database Thingy ! (You only need ONE TABLE !)

��

��

� � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � �

��

��

6

Probably You Do Not Need to

Actually Design Anything

Page 7: UKOUG 2007 - XMLDB Building Blocks & Best Practices · 10 Brilliant Stuff, This XMLDB Database Thingy ! (You only need ONE TABLE !)

��

��

� � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � �

��

��

7

"#����&�%$����'

�4���*��+���/�������+�.������������;

Page 8: UKOUG 2007 - XMLDB Building Blocks & Best Practices · 10 Brilliant Stuff, This XMLDB Database Thingy ! (You only need ONE TABLE !)

��

��

� � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � �

��

��

8

"#����&�%$����'

�4���*��+���/�������+�.������������;

� (��)���������

OBJECT*object_idnameownercreated…

ATTRIBUTES*attribute_idattribute_nameattribute_type…

OBJ_ATTR_VALUES*object_id*attribute_idattribute_nameattribute_type…

LINKS*object_id1*object_id2…

Page 9: UKOUG 2007 - XMLDB Building Blocks & Best Practices · 10 Brilliant Stuff, This XMLDB Database Thingy ! (You only need ONE TABLE !)

��

��

� � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � �

��

��

9

"#����&�%$����'

�4���*��+���/�������+�.������������;

� .���<���.�����!*� ������

� ����+�.����� ��.���+�����������������=

Create table Object( object_id number primary key,

data +,��&-� );

Page 10: UKOUG 2007 - XMLDB Building Blocks & Best Practices · 10 Brilliant Stuff, This XMLDB Database Thingy ! (You only need ONE TABLE !)

��

��

� � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � �

��

��

10

�����

Brilliant Stuff, This XMLDB Database

Thingy !(You only need ONE TABLE !)

Page 11: UKOUG 2007 - XMLDB Building Blocks & Best Practices · 10 Brilliant Stuff, This XMLDB Database Thingy ! (You only need ONE TABLE !)

��

��

� � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � �

��

��

11

�.�/ ,��&�� 0������ �$��/� #1�2

'�) ������ )�;

1�+� ������ )�;

Page 12: UKOUG 2007 - XMLDB Building Blocks & Best Practices · 10 Brilliant Stuff, This XMLDB Database Thingy ! (You only need ONE TABLE !)

��

��

� � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � �

��

��

12

/���3��)����� $��4 �$5���

Create table Object

( data +,��&-� );

0�������& #�

����1$�

0�������& #�

����1$�

Page 13: UKOUG 2007 - XMLDB Building Blocks & Best Practices · 10 Brilliant Stuff, This XMLDB Database Thingy ! (You only need ONE TABLE !)

��

��

� � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � �

��

��

13

CREATE TABLE "MARCO".“OBJECT" OF "SYS"."XMLTYPE"XMLSCHEMA "http://www.myserver.com/myapp/1.0/xsd/object.xsd"

ELEMENT “ROOT" ID 4733 PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGINGSTORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)TABLESPACE "USERS“

VARRAY "XMLEXTRA"."NAMESPACES" STORE AS BASICFILE LOB"NAMESPACES660_L"(ENABLE STORAGE IN ROW CHUNK 8192 PCTVERSION 10 CACHESTORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT))

VARRAY "XMLEXTRA"."EXTRADATA" STORE AS BASICFILE LOB"EXTRADATA659_L"(ENABLE STORAGE IN ROW CHUNK 8192 PCTVERSION 10 CACHESTORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT))

30�55�$4 �����������1$�(���#���

��6���,�'�& #��� $���$���7 �� ���� �$5�������� ����1$

��6���,�'�& #��� $���$���7 �� ���� �$5�������� ����1$

������� ����1$������� ����1$

Page 14: UKOUG 2007 - XMLDB Building Blocks & Best Practices · 10 Brilliant Stuff, This XMLDB Database Thingy ! (You only need ONE TABLE !)

��

��

� � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � �

��

��

14

&�)����� $�� �$5���

� � ���1 ��8!��,#���� ,� ��/98!:��/;

� ����3���)� �+>�&��� �)>�2���� �

���+�������*68�! ������- ����1����;

� �238����* � �+>�2��� �����+>�3����� ��>�.��/ � �+

� ��)���-�2���?� �(�0.��� ��< � �)��90���� ���� ���/���:

� ���/�������*�� @�� �� ���-�

� �.�����)+

� 3*!��<��� �����<������1�����.����"�A.��+��'��).�)�

� ��$���$�<����&>����7 �,�$��>����<����&

� ����5��� 7�8$$ ���� $����� 5��$5�6��$5��5�

Page 15: UKOUG 2007 - XMLDB Building Blocks & Best Practices · 10 Brilliant Stuff, This XMLDB Database Thingy ! (You only need ONE TABLE !)

��

��

� � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � �

��

��

15

� ��$& #,#����� ����

�- ��������)�

�%&'����/���

� ��� ,�

� ��*$�<��5

����������

� ��������� �� ���������

� &��������������!� ��

� 2�*!� ���������������

� �� ���' ������-����

� 2����!�����<���%B0�&�

� ������������� � ���!���������������!���������!� ������"��#�$%&����� ������

Page 16: UKOUG 2007 - XMLDB Building Blocks & Best Practices · 10 Brilliant Stuff, This XMLDB Database Thingy ! (You only need ONE TABLE !)

��

��

� � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � �

��

��

16

��6���,���

Page 17: UKOUG 2007 - XMLDB Building Blocks & Best Practices · 10 Brilliant Stuff, This XMLDB Database Thingy ! (You only need ONE TABLE !)

��

��

� � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � �

��

��

17

� ����� #�5& #���� �$� ��� #$�=

� 1���� ����1$

� %&'�3��������"���.*���

� %&'�����*�������%$$ ���� $��>�%&'��,��.� ��>�C�� ��� ��

� ��&����� ����1$

� ����������/����"������)���� )��/���� �� %&'�'�) ��� �� )�

� ���+�����)�������+!���>�2�*!������>�C�� ��� ��>��,��.� ��;�

� 8$5�+�������>�3��>�%&'3��� >�-.��� �� ����>��� ��

8��& #� ��5�����!"#�$#�� � �"!%�$#��5����$=

/��$��$'�%�����������> /����-��,�?�� > ���7 �,�$��

Page 18: UKOUG 2007 - XMLDB Building Blocks & Best Practices · 10 Brilliant Stuff, This XMLDB Database Thingy ! (You only need ONE TABLE !)

��

��

� � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � �

��

��

18

@ $�� ���A #� ����1$

� ��$���$�5, ������)�- ��� �&

� �����)�>��,��.� ��>����.� �+

� �����)����� /� ��������� +

�� ���.������*����

� 2'�

� ���+%&'���''�������24�&��

� !�,��-��������.�� ,����� ;=�

� �������5��.� ���!��� �)�

� ����%$$ ���� $���,�� �<�.���� ��8

� �����)�>����, �.�>���*�

Page 19: UKOUG 2007 - XMLDB Building Blocks & Best Practices · 10 Brilliant Stuff, This XMLDB Database Thingy ! (You only need ONE TABLE !)

��

��

� � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � �

��

��

19

����%$$ ���� $�

!����5�/�<���!����5�/�<���

Page 20: UKOUG 2007 - XMLDB Building Blocks & Best Practices · 10 Brilliant Stuff, This XMLDB Database Thingy ! (You only need ONE TABLE !)

��

��

� � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � �

��

��

20

�+�$1 1���� �$5���&����� ����1$

Page 21: UKOUG 2007 - XMLDB Building Blocks & Best Practices · 10 Brilliant Stuff, This XMLDB Database Thingy ! (You only need ONE TABLE !)

��

��

� � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � �

��

��

21

��$����� � �$#�� @����� $

� ��$����� ������6B�6@0*%

� %&'�����*������

� %�������� ���

� B�,���!�� �� %&'�!+

� �$#�� @����� $

� &�D&�������5��D'

� �C�������� �)�

E ���������� ��������,����FG��$�#���������*������� ��<���,��GH�

E "������"� �)"��/*�" *��/"%&'"�����

� 6�� ���������)�)������ �� �� �!!�+ ���$)0(��3���IJ��0���

Page 22: UKOUG 2007 - XMLDB Building Blocks & Best Practices · 10 Brilliant Stuff, This XMLDB Database Thingy ! (You only need ONE TABLE !)

��

��

� � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � �

��

��

22

@�����$16� ��1��6��#��#���9�);

SQL> BEGIN DBMS_XMLSCHEMA.registerSchema(SCHEMAURL => 'http://www.myserver.com/root.xsd', SCHEMADOC => xdbURIType('/public/root.xsd').getClob(), LOCAL => TRUE, -- localGENTYPES => TRUE, -- generate object types GENBEAN => FALSE, -- no java beans GENTABLES => TRUE, -- generate object tablesOWNER => USER);

END; /

Page 23: UKOUG 2007 - XMLDB Building Blocks & Best Practices · 10 Brilliant Stuff, This XMLDB Database Thingy ! (You only need ONE TABLE !)

��

��

� � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � �

��

��

23

)��#���<C����)����� $�� 6� ��1�

SQL> select * from tab;

TNAME TABTYPE------------------------------ -------INFO_TABLE TABLEROOT_TABLE TABLE

SQL> select dbms_metadata.get_ddl('TABLE','ROOT_TABLE') from dual;

DBMS_METADATA.GET_DDL('TABLE','ROOT_TABLE')------------------------------------------------------CREATE TABLE "MARCO"."ROOT_TABLE" OF "SYS"."XMLTYPE"XMLSCHEMA "http://www.myserver.com/root.xsd" ELEMENT "ROOT"PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING

STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)TABLESPACE "USERS"

VARRAY "XMLEXTRA"."NAMESPACES" STORE AS BASICFILE LOB "NAMESPACES780_L"...

VARRAY "XMLDATA"."INFO"."SYS_XDBPD$" STORE AS BASICFILE LOB "SYS_XDBP..."DISALLOW NONSCHEMA ...

Page 24: UKOUG 2007 - XMLDB Building Blocks & Best Practices · 10 Brilliant Stuff, This XMLDB Database Thingy ! (You only need ONE TABLE !)

��

��

� � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � �

��

��

24

@�����$16� ��1��6��#��#���9��$��&;

SQL> BEGIN DBMS_XMLSCHEMA.registerSchema(SCHEMAURL => 'http://www.myserver.com/root.xsd', SCHEMADOC => xdbURIType('/public/root.xsd').getClob(), LOCAL => TRUE, -- localGENTYPES => FALSE, -- generate object types GENBEAN => FALSE, -- no java beans GENTABLES => TRUE, -- generate object tablesOPTIONS => DBMS_XMLSCHEMA.REGISTER_BINARYXML, OWNER => USER);

END; /

Page 25: UKOUG 2007 - XMLDB Building Blocks & Best Practices · 10 Brilliant Stuff, This XMLDB Database Thingy ! (You only need ONE TABLE !)

��

��

� � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � �

��

��

25

)��#����$��&��6� ��1�

SQL> select * from tab;

TNAME TABTYPE------------------------------ -------ROOT_TABLE TABLE

SQL> select dbms_metadata.get_ddl('TABLE','ROOT_TABLE') from dual;

DBMS_METADATA.GET_DDL('TABLE','ROOT_TABLE')------------------------------------------------CREATE TABLE "MARCO"."ROOT_TABLE" OF "SYS"."XMLTYPE"XMLTYPE STORE AS BASICFILE BINARY XML (

TABLESPACE "USERS" ENABLE STORAGE IN ROW CHUNK 8192 PCTVERSION 10NOCACHE LOGGINGSTORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT))

XMLSCHEMA "http://www.myserver.com/root.xsd" ELEMENT "ROOT"DISALLOW NONSCHEMA ...TABLESPACE "USERS"

Page 26: UKOUG 2007 - XMLDB Building Blocks & Best Practices · 10 Brilliant Stuff, This XMLDB Database Thingy ! (You only need ONE TABLE !)

��

��

� � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � �

��

��

26

� (#$��� $�

� %&' �C�� ����

� �����*�C�� ����

� �����*�C�� �������

���������)0�

� ��$��&��6� ��1���-�� $

� K��%&'�24�&�

� K���''�����L�24�&�

� �3���''�������24�&�

��D���5��� $

#�#���&

*+��#����

#�#���&

*+��#����

� �� ��5#���

� �������*�C�� ��������

� ����*�C�� ������

Page 27: UKOUG 2007 - XMLDB Building Blocks & Best Practices · 10 Brilliant Stuff, This XMLDB Database Thingy ! (You only need ONE TABLE !)

��

��

� � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � �

��

��

27

6&$��+*+�,-�� E>;

SQL> create table "XML_XSD01" of XMLTYPE2 XMLTYPE STORE AS BASICFILE BINARY XML3 XMLSCHEMA "http://www.myserver.com/root.xsd" 4 ELEMENT "ROOT"5 ALLOW NONSCHEMA;

Table created.

SQL> create table "XML_XSD02_BUG" of XMLTYPE2 XMLTYPE STORE AS BASICFILE BINARY XML3 XMLSCHEMA "http://www.myserver.com/root.xsd" 4 ELEMENT "ROOT"5 ALLOW ANYSCHEMA6 DISALLOW NONSCHEMA;

Table created. Oops...B.6396229

Page 28: UKOUG 2007 - XMLDB Building Blocks & Best Practices · 10 Brilliant Stuff, This XMLDB Database Thingy ! (You only need ONE TABLE !)

��

��

� � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � �

��

��

28

6� ��1��6��#��#���

Page 29: UKOUG 2007 - XMLDB Building Blocks & Best Practices · 10 Brilliant Stuff, This XMLDB Database Thingy ! (You only need ONE TABLE !)

��

��

� � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � �

��

��

29

@�����<C����)����� $������$��&�

%&'�+!����/����

%&'�+!�C ���

%&'����������)�

��/M�����0���� ������/M����

0���� �������/���

0���� ����������

%&'������

���+�%&' ���.��.���

& ����*!�� N+O3��0L%��N+"�O%&'3���

2��������*!�� N�O�0%��N+O����>�3��

4+/� �

2��������*!�� N�O& ��%��N+O����>�3��

6����.��.���

��.*�����2'�%��N�O%&'3���

Page 30: UKOUG 2007 - XMLDB Building Blocks & Best Practices · 10 Brilliant Stuff, This XMLDB Database Thingy ! (You only need ONE TABLE !)

��

��

� � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � �

��

��

30

6 ,� ��6� ��1��8��#��

PPQ������"�3���

QQQ-.��� ���"��� �

QFP%&'3���

QPQQ&�*��+�&���)�*���

QQQP����.)�!.�

QPQQ%1����1��<��*����

QPQQ&'

PQP�� ���!���

QPQ����*������

��$��&��@���.).

Page 31: UKOUG 2007 - XMLDB Building Blocks & Best Practices · 10 Brilliant Stuff, This XMLDB Database Thingy ! (You only need ONE TABLE !)

��

��

� � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � �

��

��

31

�8!�*���$5�+

���&'��� $���&��#�$(

� �1��43>�03�

� �0��

")�$)��#�$(

� �03>��0�0D7�L�

� �0��

*� %$��#�$(

� ��6��0�RC�'6�R>�>�S����

� -6�2�3������

� ��� �8�!� ��������%&'�<��)*����

03

0��3

�������

0��

,��.�

,������(��$$$�

!���3

0��

�����T�+

0��

Page 32: UKOUG 2007 - XMLDB Building Blocks & Best Practices · 10 Brilliant Stuff, This XMLDB Database Thingy ! (You only need ONE TABLE !)

��

��

� � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � �

��

��

32

�8$5�+��,� � �����)���#�

�'�) ��� 3��� ���� )��� <�� ����%&'���*� ��

� 90�, ,��: �<�2'�������)����������

�6������6#<�����$1

� -.������� %&'3��� ��� /� 35�

� ��T�� ��/�����%�%U�������

� A.��+�0��� �� �� ��T���

� -.@@+��������>�""

�2�� /� *� ��� ��� &��.���+

� ����?� �.!!��������%1���� !���� ��� 1������/��

%&'3���

%&'�3�<��*�� ��

Page 33: UKOUG 2007 - XMLDB Building Blocks & Best Practices · 10 Brilliant Stuff, This XMLDB Database Thingy ! (You only need ONE TABLE !)

��

��

� � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � �

��

��

33

�8$5�+*+�,-���

SQL> CREATE INDEX XMLIX_INFO on INFO_TABLE (object_value)2 INDEXTYPE IS XDB.XMLIndex;

SQL> CREATE INDEX XMLIX_ROOT on ROOT_TABLE (object_value)2 INDEXTYPE IS XDB.XMLIndex3 PARAMETERS ('PATHS (INCLUDE (/ROOT/ID4 /ROOT/INFO/INFO_ID5 )6 NAMESPACE MAPPING

(xmlns="http://www.myserver.com/root.xsd"))7 PATH TABLE XMLBIN_PATH_TABLE8 PATH ID INDEX XMLBIN_PATHID_IX9 ORDER KEY INDEX XMLBIN_ORDERKEY_IX');

Page 34: UKOUG 2007 - XMLDB Building Blocks & Best Practices · 10 Brilliant Stuff, This XMLDB Database Thingy ! (You only need ONE TABLE !)

��

��

� � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � �

��

��

34

����$��&�-�� $�

SQL> CREATE TABLE "ROOT_TABLE" OF "SYS"."XMLTYPE"

2 XMLTYPE STORE AS SECUREFILE BINARY XML 3 XMLSCHEMA

"http://www.myserver.com/root.xsd" ELEMENT "ROOT" 4 DISALLOW NONSCHEMA

5 COMPRESS

6 ;

SQL> alter table "ROOT_TABLE"2 modify lob (XMLDATA)

3 (COMPRESS HIGH);

-- ALTER TABLE "ROOT" MODIFY LOG (XMLDATA)

-- COMPRESS | NOCOMPRESS | COMPRESS MEDIUM | COMPRESS HIGHB.6364855

Page 35: UKOUG 2007 - XMLDB Building Blocks & Best Practices · 10 Brilliant Stuff, This XMLDB Database Thingy ! (You only need ONE TABLE !)

��

��

� � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � �

��

��

35

)���-2

� ����� �����������<���� )����� � ��� ���*�T�V

� ����� ��*���������������� +�.��.�� � �� <��V

� �� )��� �� <.�.�� ��*���� ��* �� =

� ����� ���� .� ,����� ���.� �� <�� %&'�����>�+��V

.� ���� �,���+�.��V

V+�.� �� ��,�����)������9-.���&���+:H

Page 36: UKOUG 2007 - XMLDB Building Blocks & Best Practices · 10 Brilliant Stuff, This XMLDB Database Thingy ! (You only need ONE TABLE !)

��

��

� � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � �

��

��

36

)�7���$���

�%&'��,���!��� 5. ��

� ����%&'�-��.*

� ���!8""<��.*�����������*"<��.*�"<��.*�M�!�;<��.*3F��

�%&'��-�A��������

� ���!8""<��.*�����������*"<��.*�"�������M�!�;������3F��$���

� ��)

� ���!8""��������)+��* ����"/��)

� ���!8""/��)�)��� T����*

� ��T��*������!8""��T��*����������*�9- ���: ���� ���

�C��+�)����<.��<���&��T���T�?������������<<����

Page 37: UKOUG 2007 - XMLDB Building Blocks & Best Practices · 10 Brilliant Stuff, This XMLDB Database Thingy ! (You only need ONE TABLE !)

��

��

� � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � �

��

��

37

"#���� $�=

*�����)��� T�W�* ����

���!8""�����* ����