我试图编写SQL来将一行从一个表复制到另一个表但我在WHERE子句中一直得到一个无效的标识符。我使用的是oracle apex。
这是我的代码:
INSERT INTO CRIMECLOSED (crimeClosedID, crimeName, crimeDate, crimeNotes,
outsideSourceDescription, dateClosed, relatedCrimes,
staffID, crimeTypeID, locationID)
SELECT CRIMEOPEN.crimeOpenID, CRIMEOPEN.crimeName, CRIMEOPEN.crimeDate,
CRIMEOPEN.crimeNotes, CRIMEOPEN.outsideSourceDescription, CURDATE(),
CRIMEOPEN.relatedCrimes, CRIMEOPEN.staffID, CRIMEOPEN.crimeTypeID,
CRIMEOPEN.locationID
FROM CRIMEOPEN
WHERE CRIMEOPEN.crimeOpenID = '1';
CRIMEOPEN表
CREATE TABLE "CRIMEOPEN"
( "crimeOpenID" VARCHAR2(5),
"crimeName" VARCHAR2(20),
"crimeDate" DATE,
"crimeNotes" VARCHAR2(200),
"outsideSourceDescription" VARCHAR2(200),
"relatedCrimes" VARCHAR2(5),
"staffID" VARCHAR2(5),
"crimeTypeID" VARCHAR2(5),
"locationID" VARCHAR2(5),
CONSTRAINT "CRIMEOPEN_PK" PRIMARY KEY ("crimeOpenID") ENABLE
)
我得到的错误是:
ORA-00904:" CRIMEOPEN"。" CRIMEOPENID":无效标识符
我认为错误在于试图说出“犯罪贿赂”。不是“CRIMEOPEN'”中的专栏。但它是。 有什么帮助吗?
答案 0 :(得分:2)
如果在声明表格的列时使用双引号,那么当"使用"时,也需要使用相同的格式。各种陈述中的列。
因此,为了解决这个问题,你应该在select语句中用双引号括起所有列(如下所示 - 仅适用于select语句)。
INSERT INTO CRIMECLOSED (crimeClosedID, crimeName, crimeDate, crimeNotes,
outsideSourceDescription, dateClosed, relatedCrimes,
staffID, crimeTypeID, locationID)
SELECT "CRIMEOPEN"."crimeOpenID", "CRIMEOPEN"."crimeName", "CRIMEOPEN"."crimeDate",
"CRIMEOPEN"."crimeNotes", "CRIMEOPEN"."outsideSourceDescription", CURDATE(),
"CRIMEOPEN"."relatedCrimes", "CRIMEOPEN"."staffID", "CRIMEOPEN"."crimeTypeID",
"CRIMEOPEN"."locationID"
FROM "CRIMEOPEN"
WHERE "CRIMEOPEN"."crimeOpenID" = '1';