我正在尝试通过 id 列(数字类型但不是 int)中的磨丝器值来增加序列。为此,我尝试声明一个 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

最佳答案

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
execute immediate 中的任何 DDN 使用 anonymous block

关于sql - Oracle11g 变量声明,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31944682/

10-12 14:17
查看更多