Oracle:PostgreSQL 中是否有相当于 ROW 的工具?
当我在 PostgreSQL 中实例化一个类型时,我可以直接将
INSERT INTO mountain VALUES ('Meru',4567,ROW(6.8,-3.2));
ROW(...) 类型转换为表中对应的类型。在 Oracle 中,我必须这样做:
INSERT INTO mountain VALUES ('Meru',4567,GeoCoord(6.8,-3.2));
并手动将类型放入 INSERT 中。
有没有办法让 Oracle 表现得像 Postgres 一样?
编辑:表定义
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)));
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)));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Oracle 中 PostgreSQL 的 ROW 构造函数的等效项是 对象或集合构造函数,如您在发布的代码中所示。
然而,没有单一表达式可以创建所需类型的实例。来自 Oracle 11g R2 数据库文档 ,显然必须显式调用构造函数来创建和引用类型:
另外,请注意,默认构造函数适用于所有类型(关联数组除外),因此您实际上不需要编写自己的构造函数。
当考虑使用 CREATE TYPE 语句创建的架构级别类型时,行为也没有差异 - 在这种情况下也需要调用构造函数。来自文档:
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:
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: