Oracle: Is there an equivalent to ROW in PostgreSQL?
When I instantiate a type in PostgreSQL, I can just make,
INSERT INTO mountain VALUES ('Meru',4567,ROW(6.8,-3.2));
and the ROW(...) will be typecast to the correspondent type in the table. In Oracle I have to make it this way:
INSERT INTO mountain VALUES ('Meru',4567,GeoCoord(6.8,-3.2));
and manually put the type in the INSERT.
Is there any way to make Oracle behave like Postgres?
EDIT: Table definition
CREATE TABLE Mountain (
Name VARCHAR(20) CONSTRAINT MountainKey PRIMARY KEY,
Height NUMERIC CONSTRAINT MountainHeight
CHECK (Height >= 0),
Coordinates GeoCoord CONSTRAINT MountainCoord
CHECK (((Coordinates).Longitude >= -180) AND
((Coordinates).Longitude <= 180) AND
开发者_运维问答 ((Coordinates).Latitude >= -90) AND
((Coordinates).Latitude <= 90)));
The equivalent of the ROW constructor of PostgreSQL in Oracle is the object or collection constructor, as you've denoted in the posted code.
There is no singular expression however that would create an instance of the desired type. From the Oracle 11g R2 database documentation, it is evident that the constructor must be explicitly called to create and reference a type:
To initialize a nested table or varray, you use a constructor, a system-defined function with the same name as the collection type. This function constructs collections from the elements passed to it.
You must explicitly call a constructor for each varray and nested table variable. Associative arrays, the third kind of collection, do not use constructors. Constructor calls are allowed wherever function calls are allowed.
Additionally, note that a default constructor is available for all types (except associative arrays), so you don't really need to write your own constructors.
There is also no difference in behavior when considering schema level types that are created using a CREATE TYPE
statement - the constructor needs to be invoked in this case as well. From the documentation:
The system-defined attribute value constructor requires you to pass the constructor a value for each attribute of the type. The constructor then sets the attributes of the new object instance to those values
精彩评论