在 oracle merge/insert 命令期间列名 CLUSTER & COMMENT 出现问题
Issue with column names CLUSTER & COMMENT during merge/insert command in oracle
我有一个 table,其中两列具有名为 CLUSTER & COMMENT 的 oracle 保留关键字。我正在尝试使用 spring JDBC 中的合并命令,该命令抛出以下错误。
ORA-01747: 无效 user.table.column、table.column 或列规范
MERGE INTO TABLE DESTINATION
USING ( SELECT ? AS NAME, ? AS CLUSTER, ? AS COMMENT FROM DUAL) SOURCE
ON (SOURCE.NAME = DESTINATION.NAME)
WHEN MATCHED THEN
UPDATE SET DESTINATION.CLUSTER = SOURCE.CLUSTER, DESTINATION.COMMENT = SOURCE.COMMENT
WHEN NOT MATCHED THEN
INSERT (NAME, CLUSTER, COMMENT)
VALUES (SOURCE.NAME, SOURCE.CLUSTER,SOURCE.COMMENT)
有人能帮我解决这个问题而不更改列名吗?
如果您打算使用 reserved words 作为标识符,那么您需要使用带引号的标识符(以及数据库中使用的确切大小写):
MERGE INTO table_name DESTINATION
USING (
SELECT ? AS NAME,
? AS "CLUSTER",
? AS "COMMENT"
FROM DUAL
) SOURCE
ON (SOURCE.NAME = DESTINATION.NAME)
WHEN MATCHED THEN
UPDATE
SET DESTINATION."CLUSTER" = SOURCE."CLUSTER",
DESTINATION."COMMENT" = SOURCE."COMMENT"
WHEN NOT MATCHED THEN
INSERT (NAME, "CLUSTER", "COMMENT")
VALUES (SOURCE.NAME, SOURCE."CLUSTER",SOURCE."COMMENT");
但是,更好的解决方案是将标识符更改为非保留字。
db<>fiddle here
我有一个 table,其中两列具有名为 CLUSTER & COMMENT 的 oracle 保留关键字。我正在尝试使用 spring JDBC 中的合并命令,该命令抛出以下错误。
ORA-01747: 无效 user.table.column、table.column 或列规范
MERGE INTO TABLE DESTINATION
USING ( SELECT ? AS NAME, ? AS CLUSTER, ? AS COMMENT FROM DUAL) SOURCE
ON (SOURCE.NAME = DESTINATION.NAME)
WHEN MATCHED THEN
UPDATE SET DESTINATION.CLUSTER = SOURCE.CLUSTER, DESTINATION.COMMENT = SOURCE.COMMENT
WHEN NOT MATCHED THEN
INSERT (NAME, CLUSTER, COMMENT)
VALUES (SOURCE.NAME, SOURCE.CLUSTER,SOURCE.COMMENT)
有人能帮我解决这个问题而不更改列名吗?
如果您打算使用 reserved words 作为标识符,那么您需要使用带引号的标识符(以及数据库中使用的确切大小写):
MERGE INTO table_name DESTINATION
USING (
SELECT ? AS NAME,
? AS "CLUSTER",
? AS "COMMENT"
FROM DUAL
) SOURCE
ON (SOURCE.NAME = DESTINATION.NAME)
WHEN MATCHED THEN
UPDATE
SET DESTINATION."CLUSTER" = SOURCE."CLUSTER",
DESTINATION."COMMENT" = SOURCE."COMMENT"
WHEN NOT MATCHED THEN
INSERT (NAME, "CLUSTER", "COMMENT")
VALUES (SOURCE.NAME, SOURCE."CLUSTER",SOURCE."COMMENT");
但是,更好的解决方案是将标识符更改为非保留字。
db<>fiddle here