Oracle Database 12c Enterprise Edition Release 12.1.0.2.0-64位
生产PL/SQL版本12.1.0.2.0-生产
适用于64位Windows的"CORE 12.1.0.2.0 Production"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 GENERATED身份总是以8开头);
错误
在命令的第1行开始时出错-声明mvalue INTEGER;exp
varchar(1000);开始从中选择max(合并(ID,0))+1为mvalue
动作日志;exp:='ALTER TABLE ACTIONLOG MODIFY(ID GENERATED ALWAYS
AS IDENTITY以'||mvalue||'开始);';dbms_output.Put_line('最大
值:'||mvalue);DBMS_OUTPUT.PUT_LINE('表达式:'||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 ||')';
试试这个
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;
/