要在 SQL 语句中引用对象类型属性或方法,必须使用表别名完全限定该引用。以下示例中样本 Schema ob 包含类 cust_address_typ 和表 customers,customers 拥有一个 cust_address_typ 类型的列 cust_address:
CREATE TYPE cust_address_typ
OID '82A4AF6A4CD1656DE034080020E0EE3D'
AS OBJECT
(street_address VARCHAR2(40),
postal_code VARCHAR2(10),
city VARCHAR2(30),
state_province VARCHAR2(10),
country_id CHAR(2));
/
CREATE TABLE customers
(customer_id NUMBER(6),
cust_first_name VARCHAR2(20) CONSTRAINT cust_fname_nn NOT NULL,
cust_last_name VARCHAR2(20) CONSTRAINT cust_lname_nn NOT NULL,
cust_address cust_address_typ,
. . .
在 SQL 语句中,对 postal_code 属性的引用必须使用表别名进行完全限定,如下所示:
SELECT c.cust_address.postal_code
FROM customers c;
UPDATE customers c
SET c.cust_address.postal_code = '610000'
WHERE c.cust_address.city = 'chengdu'
AND c.cust_address.state_province = 'SICHUAN';
要引用不接受参数的成员方法,必须提供空括号。例如,样本 Schema ob 包含一个基于 catalog_typ 的对象表 category_tab,该表包含成员函数 getCatalogName
。为了在 SQL 语句中调用此方法,必须提供空括号,如下所示:
SELECT TREAT(VALUE(c) AS catalog_typ).getCatalogName() "Catalog Type"
FROM categories_tab c
WHERE category_id = 10;
返回结果:
+----------------+
| Catalog Type |
+----------------+
| online catalog |
+----------------+
作者:andy,如若转载,请注明出处:https://www.web176.com/oceanbase/26371.html