Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Seeking Equivalent of InterBase Domain
Serge Rielau wrote:
> You would need to build a constructor for the structured type.
> The constructor will contain the constraint.
Yes but unless I'm missing something, one limitation of object types is that a user-defined constructor must differ in signature from the system-defined one. Why do I bother ;)
> Then is all boils down whether Oracle supports implicit casting for
> structured types.
> I.e. Can you just pass a string and it will automagically invoke the
> constructor?
If you used the above BOOL_DOM object type for a table column you would have to use constructor syntax to set its value:
INSERT INTO employees (is_director) VALUES (BOOL_DOM('Y'));
Note that in this example if BOOL_DOM has one character string attribute then the above constructor *has* to be the system-defined one, which means it *cannot* include any additional custom processing. You might get around this by adding a dummy attribute so that you could add a custom constructor with only one argument.
> IF that hurdle is overcome the next problem is indexing.
> Instead of normal indexing I presume one would need to define indexes on
> the observer methods of the type.
I'm not sure what an observer method is but you would have to specify the object.attribute as with the column-level constraint suggested earlier:
SQL> CREATE TYPE name_ot AS OBJECT (name VARCHAR2(40)); 2 /
Type created.
SQL> CREATE TABLE bananas (id INT PRIMARY KEY, name NAME_OT);
Table created.
SQL> CREATE INDEX banaans_ix ON bananas(name); CREATE INDEX banaans_ix ON bananas(name)
*
SQL> CREATE INDEX banaans_ix ON bananas(name.name);
Index created. Received on Tue Jan 23 2007 - 08:48:14 CST