oracle序列旨在返回自动递增的数字。我想知道我是否可以实现一个自定义的序列,该序列从我放入的值池中返回,以便我可以告诉序列预期返回的结果。如何实现自定义oracle序列?
无论如何要实施这个?或替代,如添加触发器,或Oracle功能或其他任何东西?
甚至使用表保存价值,但怎么做才是最好的性能,像ORALCE序列
I have this, but not sure is it the best one.
create table your_table(
gap_from int,
gap_to int
);
insert into your_table values(99999, 9998888);
insert into your_table values(2, 7);
insert into your_table values(200, 10000);
insert into your_table values(10001, 300000);
create table2 as select
gap_from,
1 + nvl(sum(gap_to - gap_from + 1) over (order by gap_from rows between unbounded preceding and 1 preceding), 0) as seq_from,
sum(gap_to - gap_from + 1) over (order by gap_from) as seq_to
from your_table;
create sequence your_new_seq;
create or replace function get_PK_inside_gap return number as
new_seq_val number;
PK_inside_gap number;
begin
select your_new_seq.nextval into new_seq_val from dual;
execute immediate '
select
new_seq_val + gap_from - seq_from
from
(select :1 as new_seq_val from dual)
join (
table2
) on new_seq_val between seq_from and seq_to'
into PK_inside_gap using new_seq_val;
return PK_inside_gap;
end;
它可能取决于你想得到什么,你能举个例子吗? – 2013-03-10 14:28:07
例如,我想开发一个自定义的序列,它返回范围[2,7],[200,10000],[10001,300000],[99999,9998888]等等......所以我想在这里从特定范围获得自动增加。 – 2013-03-10 14:39:06