Oracle SQL 创建或替换视图 with/without 列名

Oracle SQL create or replace view with/without column names

我有一个关于 Oracle 中的视图的问题。假设我们创建了一个视图:

Create View V1(col1, col3, col2) as
(
  select a as col1,
         b as col2,
         c as col3
   from x.y
)

然后让我们说你发现你现在 select 错了,因为你 select 它是:

select col1, col2, col3 
from V1 
--Expecting col1, col2, col3
--but gets  col1, col3, col2

现在您创建或替换时没有 header 个名称

Create or replace force editionable View V1 as
(
  select a as col1,
         b as col2,
         c as col3
   from x.y
)

现在您仍然遇到同样的问题。因此我的问题是: 当您创建定义 header 的视图时,Oracle 是否将 header 名称的位置存储在某处并且需要在 select 正确通过之前重新加载?

不幸的是,Oracle 只检查查询文本,因为它没有被更改,Oracle 并没有真正重建它。

稍微修改一下文字就可以了:


SQL> create or replace view v1(a,c,b) as select 'a' a,'b' b,'c' c from dual;

View created.

SQL> select * from v1;

A C B
- - -
a b c

SQL> create or replace view v1(a,b,c) as select 'a' a,'b' b,'c' c from dual;

View created.

SQL> select * from v1;

A C B
- - -
a b c

-- I've added just one extra space after dual:
SQL> create or replace view v1(a,b,c) as select 'a' a,'b' b,'c' c from dual ;

View created.

SQL> select * from v1;

A B C
- - -
a b c

PS。此错误仅存在于 Oracle 19+ 上。我已经在 11.2.0.4 和 18.5 上检查过了,一切正常。注册SR比较好。如果你想让我注册,请告诉我