问题
The database I'm querying is Oracle 12c. Detailed info about database version is as follows:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
PL/SQL Release 12.1.0.2.0 - Production
I'm trying to eliminate the need to have double quotes around every view or table in my SQL query.
Following works (from Oracle Sql Developer GUI)
select m."Metadata"
from "EvMetadata" m
Following gives error (from Oracle Sql Developer GUI)
select m.Metadata
from EvMetadata m
Error is
ORA-00942: table or view does not exist 00942. 00000 - "table or view does not exist" *Cause:
*Action: Error at Line: 2 Column: 6
I generated DDL, which looks like this
CREATE TABLE "EVP"."EvMetadata"
("EvMetadataId" NUMBER(10,0) GENERATED ALWAYS AS IDENTITY MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER NOCYCLE ,
"InsertDate" TIMESTAMP (6),
"SessionId" NVARCHAR2(17),
"FileCheckSum" NVARCHAR2(32),
"Metadata" NCLOB,
"Device" NVARCHAR2(20),
"User" NVARCHAR2(20)
) SEGMENT CREATION IMMEDIATE
So based on @toddlermenot's comment below, it is very possible that this is how the table was created - with double quotes. I used ORM Entity Framework Code First to generate the schema for me so it seems like the ORM puts the double quotes by default.
回答1:
Maybe you created the table with double quotes? Using double quotes would preserve the case and since the table name has both upper and lower case letters in your example, Oracle is able to find it only when you use the double quotes.
Without the double quotes, Oracle probably uses a single case (upper?) irrespective of any case you might have in the table, by default.
For example: if you create the table using
create table "TaBlE_NaMe" (blah..)
then you must use the double quotes in your SELECT.
If you create the table using
create table TaBlE_NaMe (blah..)
The SELECT without quote should work correctly. (It would work with the quote also if you had all the letters of the table's name in upper case)
回答2:
Names in oracle be it table, column, object, view, package, procedure, function, etc. are by default UPPER CASE unless quoted with double quotes. Furthermore, all name resolution in oracle is case sensitive.
What this means is that when you create or attempt to use a database object without quoting the name oracle will implicitly convert that name to upper case before creating the object or resolving the name. So the unquoted EvMetadata
table name is equivalent to the quoted upercase "EVMETADATA"
table name but not to the quoted mixed case "EvMetadata"
table name.
来源:https://stackoverflow.com/questions/31569953/why-does-oracle-12c-query-require-double-quotes-around-table