Skip to Main Content

Oracle Database Discussions

Enhance docs: Get object attribute using bracket syntax: (object_col).attribute

User_1871Jun 12 2022 — edited Jun 13 2022

Could a blurb be added to the docs that explains that the bracket syntax can be used to get an object's attribute?

with cte as (select sdo_geometry('point(10 20)') as shape from dual)

select
  (shape).sdo_gtype
from
  cte

(SHAPE).SDO_GTYPE
-----------------
             2001

...as an alternative to the table alias technique:
2.1.8.1 When Table Aliases Are Required

Oracle Database requires you to use a table alias to qualify any dot-notational reference to subprograms or attributes of objects, to avoid inner capture and similar problems resolving references.

with cte as (select sdo_geometry('point(10 20)') as shape from dual)

select
  a.shape.sdo_gtype
from
  cte a

I think that would be helpful to people of the future.
(It might not be a big deal for a simple query like the above example. But for a large query, eliminating the need for table aliases can help keep a query clean.)
Cheers.

Comments
Post Details
Added on Jun 12 2022
2 comments
50 views