How to create a database sequence which is different for different channels?

好久不见. 提交于 2019-12-01 14:04:27

Your question is unclear. Please describe requirements more datailed. I understand you want to have a few sequences and increment them conditionally so:

create sequence chanel1_seq INCREMENT BY 1 START WITH 1;
create sequence chanel2_seq INCREMENT BY 1 START WITH 1;
create sequence chanel3_seq INCREMENT BY 1 START WITH 1;

and then access sequence set by function not directly:

create or replace function get_seq_val(chanell in varchar2) return varchar2 is
begin
if (chanell = 'CH1') then
return 'CH1' || chanel1_seq.nextval;
elsif (chanell = 'CH2') then
return 'CH2' || chanel2_seq.nextval;
elsif (chanell = 'CH3') then
return 'CH3' || chanel3_seq.nextval;
end if;
return '';
end;

And get value by:

select get_seq_val('CH1') from dual;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!