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

前端 未结 1 1904
失恋的感觉
失恋的感觉 2021-01-17 00:15

We have one requirement where different database sequences needs to be maintained for different channels. EX: ABC-SQN1, XYZ-1, and the Sequence nos needs to be incremented b

相关标签:
1条回答
  • 2021-01-17 00:46

    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;
    
    0 讨论(0)
提交回复
热议问题