Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Increment count dynamically in oracle sql

User_AE8FXAug 5 2019 — edited Aug 6 2019

Hi All,

Oracle: 11.2

I have data like in the table.

I want to use order_num in the filter

with xxc_test

as

(

select '123-A' order_num from dual

)

if order_num 123-A in the table then create with 123-A1

with xxc_test

as

(

select '123-A1' order_num from dual

)

if Order_num in the table 123-A1 then create with 123-A2

with xxc_test

as

(

select '123-A2' order_num from dual

)

if Order_num in the table 123-A2 then create with 123-A3

I wrote like below I know it won't work.

  select count(1)

  into v_cnt

  from xxc_test

  where Order_num=c_rec.Order_num || '-A';

 

  if v_cnt <1 then

   l_order_num:=c_rec.Order_num || '-A'||v_cnt;

  else

   l_order_num:=c_rec.Order_num || '-A';

  end if;

Can you please help me?

Thank you

Comments
Post Details
Added on Aug 5 2019
10 comments
4,601 views