我尝试通过id列(numeric类型而不是int类型)中的grater值来递增序列。为此,我尝试声明一个int变量,并从表中选择最大值,如下所示:
declare
last_id int;
begin
select max(id) into last_id from my_table;
alter sequence my_table_seq increment by last_id;
end;然而,我得到了这个错误
ORA-06550: line 2, column 19:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
:= . ( @ % ; not null range default character我使用的是Oracle 11g。这是一个screenshot
发布于 2015-08-11 22:43:32
declare
last_id number;
begin
select max(id) into last_id from my_table;
execute immediate 'alter sequence my_table_seq increment by ' || to_char(last_id);
end;使用任何oracle Numeric Data Types而不是int
对anonymous block中的任何DDN使用execute immediate
发布于 2015-08-12 06:07:08
创建了类似的对象,并按预期工作。
建议您尝试以下操作:
1.将列从
ID更改为something_id。
2.删除模式和表名称中的双引号(只需提供schema.table_name)
3.确保语句末尾没有遗漏分号,并且正确声明了所有变量。如果仍然不起作用,那么使用试错法。
ID值。然后,last_id赋值,并尝试print last_id).execute immediate语句,看看它是否有效。Create table general_discount_type
(id number);
-- Table created.
Begin
insert into general_discount_type values(101);
insert into general_discount_type values(102);
insert into general_discount_type values(103);
insert into general_discount_type values(104);
End;
-- Statement processed.
Create sequence general_discount_type_seq
start with 1
increment by 1
NOCACHE
NOCYCLE;
-- Sequence created.
Declare
last_id number;
Begin
select max(id) into last_id from MAHI_SCHEMA.general_discount_type;
execute immediate 'alter sequence MAHI_SCHEMA.general_discount_type_seq increment by '
|| to_char(last_id);
dbms_output.put_line('Value in last_id is : ' || last_id);
End;
-- Value in last_id is : 104输出

https://stackoverflow.com/questions/31944682
复制相似问题