Oracle Database 12c企业版12.1.0.2.0版 - 64位
生产PL / SQL版本12.1.0.2.0 - 生产
64位Windows的“CORE 12.1.0.2.0生产”TNS:版本
12.1.0.2.0 - 生产NLSRTL版本12.1.0.2.0 - 生产
此代码运作良好
ALTER TABLE ACTIONLOG MODIFY (ID GENERATED ALWAYS AS IDENTITY START WITH 8);
但是当我使用执行立即给出错误
时declare
mvalue INTEGER;
exp varchar(1000);
begin
select max(coalesce(ID,0))+1 into mvalue from ACTIONLOG;
exp := 'ALTER TABLE ACTIONLOG MODIFY (ID GENERATED ALWAYS AS IDENTITY START WITH '|| mvalue ||');';
dbms_output.Put_line('Max Value: '|| mvalue);
DBMS_OUTPUT.PUT_LINE('Expression: ' || exp);
execute immediate exp;
end;
/
DBMS输出
最大值:8
表达式:ALTER TABLE ACTIONLOG MODIFY(ID生成 始终以身份开始8);
错误
从命令行中的错误开始:1 - 声明mvalue INTEGER; EXP
VARCHAR(1000);从
开始选择max(coalesce(ID,0))+ 1进入mvalueACTIONLOG; exp:='ALTER TABLE ACTIONLOG MODIFY(ID始终生成
AS IDENTITY START WITH'|| mvalue ||');'; DBMS_OUTPUT.PUT_LINE('最大
价值:'|| mvalue); DBMS_OUTPUT.PUT_LINE('Expression:'|| exp);
执行立即exp;结束;错误报告 - ORA-01735:ALTER TABLE
无效选项ORA-06512:第9行
- 00000 - “ALTER TABLE选项无效”
醇>*原因:
*动作:
编辑:问题是“;”
所以答案是:
exp := 'ALTER TABLE ACTIONLOG MODIFY (ID GENERATED ALWAYS AS IDENTITY START WITH '|| mvalue ||');';
而不是
exp := 'ALTER TABLE ACTIONLOG MODIFY (ID GENERATED ALWAYS AS IDENTITY START WITH '|| mvalue ||')';
答案 0 :(得分:3)
试试这个
declare
mvalue INTEGER;
exp varchar(1000);
begin
select max(coalesce(ID,0))+1 into mvalue from ACTIONLOG;
--exp := 'ALTER TABLE ACTIONLOG MODIFY (ID GENERATED ALWAYS AS IDENTITY START WITH '|| mvalue ||');';
dbms_output.Put_line('Max Value: '|| mvalue);
--DBMS_OUTPUT.PUT_LINE('Expression: ' || exp);
execute immediate 'ALTER TABLE ACTIONLOG MODIFY (ID GENERATED ALWAYS AS IDENTITY START WITH '|| mvalue ||')';
end;
/