I need to load data using SQL* Loader into Oracle table with GENERATE ALWAYS AS IDENTITY
CREATE TABLE tbl_identity
(
col1 NUMBER(10,0) GENERATED ALWAYS AS IDENTITY(START WITH 7 INCREMENT BY 1) NOT NULL,
col2 VARCHAR2(20)
);
But when I try to load data in this table, I get an error
ORA-32795: cannot insert into a generated always identity column
Maybe there are any option in SQLLDR which skip IDENTITY for a while?
Or maybe there are any ideas how I can load data into GENERATED ALWAYS IDENTITY column using SQLLDR?
SQLLDR command
sqlldr userid=user/passw@TNS control=tbl_identity.ctl log=tbl_identity.log rows=1000 readsize=65535 bindsize=65535
CTL-file
OPTIONS(direct=false)
LOAD DATA
INFILE 'tbl_identity.txt'
INTO TABLE tbl_identity
INSERT
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' TRAILING NULLCOLS
(col1,
col2)
将您的 DDL 从GENERATED ALWAYS
更改为GENERATED BY DEFAULT
I use the following script before loading the data :
begin
for rec in (
select owner, table_name, column_name, generation_type
from all_tab_identity_cols
where owner = 'owner '
and generation_type in ('ALWAYS')
and table_name in ('','',......)
)loop
-- before load data
if rec.generation_type = 'ALWAYS' then
execute immediate 'alter table '||rec.owner||'.'||rec.table_name||' modify '||rec.column_name||' generated by default as identity';
end if;
if rec.generation_type = 'BY DEFAULT' then
-- return (after data load)
execute immediate 'alter table '||rec.owner||'.'||rec.table_name||' modify '||rec.column_name||' generated always as identity';
end if;
end loop;
end;
/
and then return everything to the way it was.
Be careful, list the right tables in the query!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.