具有多个连接的 Oracle 视图仅在使用引号时才能识别 - 为什么?
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该视图是使用混合大小写名称创建的。 如果您发出以下命令(注意对象名称周围没有引号),
RDBMS 将创建视图,然后您将在 dba_views(如果看不到 dba_views,则在 user_views)中找到一行,其名称为大写的 VVIEW。 然后选择 * from karl.vview 或 ... from KARL.VVIEW 将起作用。
但是,如果您引用对象名称保留大小写,则必须再次用引号显式匹配它。 (这也将允许名称中存在空格和其他不良情况。值得了解避免并能够在发生这种情况时解决。
当然,要删除此表,我必须使用 Drop table "TesT";
The view was created with a mixed case name. If you issue the following (note no quotes around object names)
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.
Of course to drop this table I had to use Drop table "TesT";
在 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".