ORA-32795: 无法插入生成的始终标识列
ORA-32795: cannot insert into a generated always identity column
伙计们,我正在尝试执行下面的插入语句,但我一直收到错误消息:
cannot insert into a generated always identity column
语句是:
INSERT INTO leaves_approval
SELECT *
FROM requests_temp r
WHERE r.civil_number = 33322
AND r.request_id = (SELECT Max(s.request_id)
FROM requests_temp s)
您对错误有什么不理解的?您有一个 "identity" 列,其中的值作为序列生成。你不能插入它。因此,列出所有其他列:
INSERT INTO LEAVES_APPROVAL(col1, col2, col3, . . .)
SELECT col1, col2, col3, . . .
FROM REQUESTS_TEMP r
WHERE r.CIVIL_NUMBER = 33322 AND
r.REQUEST_ID = (SELECT MAX(s.REQUEST_ID) FROM REQUESTS_TEMP s);
一般来说,无论如何列出 INSERT
中的所有列是个好主意。这可以防止意外错误,因为列的顺序错误或表的列数不同。
您的目标 table (leaves_approval) 中的一列包含一个标识列,该列被定义为 始终生成。
标识列可以在 2 种模式下创建 - 始终生成,即 不能 分配和 默认生成 可以分配。
如果您愿意,可以更改列模式,然后进行插入 "as is"。
考虑到这可能会在标识列中创建重复项或由于约束而失败。
ALTER TABLE leaves_approval MODIFY **my_identity_column** GENERATED BY DEFAULT AS IDENTITY;
或者您可以从 INSERT 列表中排除标识列(但您必须指明完整的列列表,标识列除外),例如-
INSERT INTO leaves_approval (c1,c2,c3,c4,...)
SELECT c1,c2,c3,c4 ...
FROM requests_temp r
WHERE r.civil_number = 33322
AND r.request_id = (SELECT Max(s.request_id)
FROM requests_temp s)
Database SQL Language Reference - CREATE TABLE
ALWAYS If you specify ALWAYS, then Oracle Database always uses the
sequence generator to assign a value to the column. If you attempt to
explicitly assign a value to the column using INSERT or UPDATE, then
an error will be returned. This is the default.
BY DEFAULT If you specify BY DEFAULT, then Oracle Database uses the
sequence generator to assign a value to the column by default, but you
can also explicitly assign a specified value to the column. If you
specify ON NULL, then Oracle Database uses the sequence generator to
assign a value to the column when a subsequent INSERT statement
attempts to assign a value that evaluates to NULL.
示例:my_table_column NUMBER GENERATED BY DEFAULT ON NULL AS IDENTITY - 如果您将列定义为,那么它将在它为 NULL 时获取值,如果您要 insert/update 与该列的值。它对我有用。
伙计们,我正在尝试执行下面的插入语句,但我一直收到错误消息:
cannot insert into a generated always identity column
语句是:
INSERT INTO leaves_approval
SELECT *
FROM requests_temp r
WHERE r.civil_number = 33322
AND r.request_id = (SELECT Max(s.request_id)
FROM requests_temp s)
您对错误有什么不理解的?您有一个 "identity" 列,其中的值作为序列生成。你不能插入它。因此,列出所有其他列:
INSERT INTO LEAVES_APPROVAL(col1, col2, col3, . . .)
SELECT col1, col2, col3, . . .
FROM REQUESTS_TEMP r
WHERE r.CIVIL_NUMBER = 33322 AND
r.REQUEST_ID = (SELECT MAX(s.REQUEST_ID) FROM REQUESTS_TEMP s);
一般来说,无论如何列出 INSERT
中的所有列是个好主意。这可以防止意外错误,因为列的顺序错误或表的列数不同。
您的目标 table (leaves_approval) 中的一列包含一个标识列,该列被定义为 始终生成。
标识列可以在 2 种模式下创建 - 始终生成,即 不能 分配和 默认生成 可以分配。
如果您愿意,可以更改列模式,然后进行插入 "as is"。
考虑到这可能会在标识列中创建重复项或由于约束而失败。
ALTER TABLE leaves_approval MODIFY **my_identity_column** GENERATED BY DEFAULT AS IDENTITY;
或者您可以从 INSERT 列表中排除标识列(但您必须指明完整的列列表,标识列除外),例如-
INSERT INTO leaves_approval (c1,c2,c3,c4,...)
SELECT c1,c2,c3,c4 ...
FROM requests_temp r
WHERE r.civil_number = 33322
AND r.request_id = (SELECT Max(s.request_id)
FROM requests_temp s)
Database SQL Language Reference - CREATE TABLE
ALWAYS If you specify ALWAYS, then Oracle Database always uses the sequence generator to assign a value to the column. If you attempt to explicitly assign a value to the column using INSERT or UPDATE, then an error will be returned. This is the default.
BY DEFAULT If you specify BY DEFAULT, then Oracle Database uses the sequence generator to assign a value to the column by default, but you can also explicitly assign a specified value to the column. If you specify ON NULL, then Oracle Database uses the sequence generator to assign a value to the column when a subsequent INSERT statement attempts to assign a value that evaluates to NULL.
示例:my_table_column NUMBER GENERATED BY DEFAULT ON NULL AS IDENTITY - 如果您将列定义为,那么它将在它为 NULL 时获取值,如果您要 insert/update 与该列的值。它对我有用。