【问题标题】:Reset Sequence in oracle 11goracle 11g 中的重置序列
【发布时间】:2013-08-06 06:19:12
【问题描述】:

我正在尝试使用 oracle 11g 中的以下过程将序列动态重置为 1。

create or replace
procedure reset_sequence(p_seq in varchar2)
is
    l_value number;
begin

-- Select the next value of the sequence

    execute immediate
    'select ' || p_seq || 
    '.nextval from dual' INTO l_value;

-- Set a negative increment for the sequence, 
-- with value = the current value of the sequence

    execute immediate
    'alter sequence ' || p_seq || 
    ' increment by -' || l_value || ' minvalue 0';

-- Select once from the sequence, to 
-- take its current value back to 0

    execute immediate
    'select ' || p_seq || 
    '.nextval from dual' INTO l_value;

-- Set the increment back to 1

    execute immediate
    'alter sequence ' || p_seq || 
    ' increment by 1 minvalue 0';
end;
/

但是当我尝试执行重置序列circle_seq的过程时,我收到以下错误

BEGIN reset_sequence(vf_circle_seq); END;

                     *
ERROR at line 1:
ORA-06550: line 1, column 22:
PLS-00357: Table,View Or Sequence reference 'CIRCLE_SEQ' not allowed 
           in this context
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored

代码有什么问题?这在 oracle 11g 中是不可能的吗,因为我在 oracle 10g 中使用的相同代码在它工作正常之前。

【问题讨论】:

  • 试试BEGIN reset_sequence('vf_circle_seq'); END;
  • 是的。它工作得很好。我犯了错误。谢谢!
  • 我会把它作为答案发布
  • “在它正常工作之前” - 很少有人说假话...... :) 开玩笑的,我们都时常犯这样的错误 :)

标签: oracle plsql


【解决方案1】:

序列名称应作为字符串传递

BEGIN 
  reset_sequence('vf_circle_seq'); 
END;

【讨论】:

    猜你喜欢
    • 2021-07-13
    • 1970-01-01
    • 2013-03-06
    • 1970-01-01
    • 1970-01-01
    • 2014-06-06
    • 2016-12-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多