retrieve user defined datatype from table

我与影子孤独终老i 提交于 2019-12-24 11:02:08

问题


SQL> -- CASE 1

SQL>select nest_test.id.num from nest_test;
select nest_test.id.num from nest_test
       *
ERROR at line 1:
ORA-00904: "NEST_TEST"."ID"."NUM": invalid identifier

SQL> -- CASE 2

SQL>select n.id.num from nest_test n;

    ID.NUM
----------
        12

As, AFAIK, aliasing any table is just giving simple name to the table or column. Then, why I'm getting error in Case 1, when I'm trying to retrieve user defined object from table ? What actually happened, when I aliased my table.


回答1:


The Oracle documentation states that table aliases are required to reference methods or attributes of objects to avoid the potential for "inner capture" (a table column name clashing with an object attribute name). Find out more.

The documentation states:

"You must qualify a reference to an object attribute or method with a table alias rather than a table name even if the table name is itself qualified by a schema name."

It doesn't say why Oracle enforce this rule. But there is obviously some complexity in the namespace implementation, caused by retrofitting objects into the relational kernel.


"then, why this query works select emp.sal from emp"

Because that's a regular column on a table. Oracle have never enforced aliases on normal tables. Starting now would break an enormous amount of code which has accrued over the decades.

Having to use aliases is just one more penalty for using object types to define table columns. It's far from being teh most onerous aspect of the clunky syntax which goes with Oracle's ORDBMS implementation.

Besides, there's almost cases in which using objects rather than realtional tables to persist data is the rigyht solution, so it doesn't really matter.



来源:https://stackoverflow.com/questions/16077023/retrieve-user-defined-datatype-from-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!