具有多个连接的 Oracle 视图仅在使用引号时才能识别 - 为什么?

发布于 2024-07-19 05:52:11 字数 1286 浏览 3 评论 0原文

我在 Oracle 视图上执行 sql 查询时遇到了奇怪的行为。 该视图包含多个联接。 当我输入常规 sql 时:

select * from vView - I receive the error that view is not found
select * from "vView" - The query is executed. 

我想知道为什么?

下面是我的sql:

 CREATE OR REPLACE FORCE VIEW "TMSCODE"."vCountEventsData" ("EV_ID_NUMBER", "SI_ID", "EV_YEAR", "EV_INS_DATE", "EV_REM_DATE", "EV_AADT_TOT", "EV_AADT_DIR1", "EV_AADT_DIR2", "EV_REPORT", "DIRECTION", "CNAME", "STATION_DESC") AS 
SELECT
"TMSCODE"."STC_EVENTS".EV_ID_NUMBER,
"TMSCODE"."STC_EVENTS".SI_ID,
"TMSCODE"."STC_EVENTS".EV_YEAR,
"TMSCODE"."STC_EVENTS".EV_INS_DATE,
"TMSCODE"."STC_EVENTS".EV_REM_DATE,
"TMSCODE"."STC_EVENTS".EV_AADT_TOT,
"TMSCODE"."STC_EVENTS".EV_AADT_DIR1,
"TMSCODE"."STC_EVENTS".EV_AADT_DIR2,
"TMSCODE"."STC_EVENTS".EV_REPORT,
"TMSCODE"."D_DIRECTION".DIRECTION,
"TMSCODE"."D_CONSULTANT".CNAME,
"TMSCODE"."D_STATION_TYPE".STATION_DESC
FROM
"TMSCODE"."STC_EVENTS"
INNER JOIN "TMSCODE"."D_DIRECTION" ON ("TMSCODE"."STC_EVENTS".EV_DIR = "TMSCODE"."D_DIRECTION".ID)
INNER JOIN "TMSCODE"."D_CONSULTANT" ON ("TMSCODE"."STC_EVENTS".EV_CONS = "TMSCODE"."D_CONSULTANT".ID)
INNER JOIN "TMSCODE"."D_STATION_TYPE" ON ("TMSCODE"."STC_EVENTS".EV_STATION_TYPE = "TMSCODE"."D_STATION_TYPE".ID)
WITH READ ONLY

I have encountered a strange behavior while executing an sql query on the Oracle view.
The view contains multiple joins. When I type a regular sql:

select * from vView - I receive the error that view is not found
select * from "vView" - The query is executed. 

I am wondering why ?

Below is my sql:

 CREATE OR REPLACE FORCE VIEW "TMSCODE"."vCountEventsData" ("EV_ID_NUMBER", "SI_ID", "EV_YEAR", "EV_INS_DATE", "EV_REM_DATE", "EV_AADT_TOT", "EV_AADT_DIR1", "EV_AADT_DIR2", "EV_REPORT", "DIRECTION", "CNAME", "STATION_DESC") AS 
SELECT
"TMSCODE"."STC_EVENTS".EV_ID_NUMBER,
"TMSCODE"."STC_EVENTS".SI_ID,
"TMSCODE"."STC_EVENTS".EV_YEAR,
"TMSCODE"."STC_EVENTS".EV_INS_DATE,
"TMSCODE"."STC_EVENTS".EV_REM_DATE,
"TMSCODE"."STC_EVENTS".EV_AADT_TOT,
"TMSCODE"."STC_EVENTS".EV_AADT_DIR1,
"TMSCODE"."STC_EVENTS".EV_AADT_DIR2,
"TMSCODE"."STC_EVENTS".EV_REPORT,
"TMSCODE"."D_DIRECTION".DIRECTION,
"TMSCODE"."D_CONSULTANT".CNAME,
"TMSCODE"."D_STATION_TYPE".STATION_DESC
FROM
"TMSCODE"."STC_EVENTS"
INNER JOIN "TMSCODE"."D_DIRECTION" ON ("TMSCODE"."STC_EVENTS".EV_DIR = "TMSCODE"."D_DIRECTION".ID)
INNER JOIN "TMSCODE"."D_CONSULTANT" ON ("TMSCODE"."STC_EVENTS".EV_CONS = "TMSCODE"."D_CONSULTANT".ID)
INNER JOIN "TMSCODE"."D_STATION_TYPE" ON ("TMSCODE"."STC_EVENTS".EV_STATION_TYPE = "TMSCODE"."D_STATION_TYPE".ID)
WITH READ ONLY

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小苏打饼 2024-07-26 05:52:11

该视图是使用混合大小写名称创建的。 如果您发出以下命令(注意对象名称周围没有引号),

create view karl.vView 
as 
(select * from dba_tables);

RDBMS 将创建视图,然后您将在 dba_views(如果看不到 dba_views,则在 user_views)中找到一行,其名称为大写的 VVIEW。 然后选择 * from karl.vview 或 ... from KARL.VVIEW 将起作用。

但是,如果您引用对象名称保留大小写,则必须再次用引号显式匹配它。 (这也将允许名称中存在空格和其他不良情况。值得了解避免并能够在发生这种情况时解决。

SYS@icedev> create table "TesT" (a int);

Table created.

SYS@icedev> insert into TesT values (1);
insert into TesT values (1)
            *
ERROR at line 1:
ORA-00942: table or view does not exist


SYS@icedev> insert into test values (1);
insert into test values (1)
            *
ERROR at line 1:
ORA-00942: table or view does not exist


SYS@icedev> insert into "TesT" values (1);

1 row created.

当然,要删除此表,我必须使用 Drop table "TesT";

The view was created with a mixed case name. If you issue the following (note no quotes around object names)

create view karl.vView 
as 
(select * from dba_tables);

The RDBMS will create the view and you will then find a line in dba_views (or user_views if you can't see dba_views) with the name VVIEW in upper case. Then select * from karl.vview or ... from KARL.VVIEW will work

If however you quote the objects names retains the case and you have to explicitly match it again with quotes. (This will also allow spaces in names and other bad scenarios. Worth knowing about to avoid and to be able to resolve when it does happen.

SYS@icedev> create table "TesT" (a int);

Table created.

SYS@icedev> insert into TesT values (1);
insert into TesT values (1)
            *
ERROR at line 1:
ORA-00942: table or view does not exist


SYS@icedev> insert into test values (1);
insert into test values (1)
            *
ERROR at line 1:
ORA-00942: table or view does not exist


SYS@icedev> insert into "TesT" values (1);

1 row created.

Of course to drop this table I had to use Drop table "TesT";

久随 2024-07-26 05:52:11

在 Oracle 中,除非加引号,否则对象的名称均为大写。
您使用引号创建了一个具有大小写混合名称的对象,因此您现在必须始终使用带引号的标识符来引用该对象,以表示“不要将其更改为大写”。

In Oracle, objects have an uppercase name unless quoted.
You used quotes to create an object with a mixed case name, so you must now ALWAYS refer to the object using a quoted identifier to say "Don't change this to uppercase".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文