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!

replace and instr function

AMar 15 2011 — edited Mar 15 2011
my query as below:
declare
i                      number;
V_position             number:=0;
V_LENGTH               NUMBER;
V_VALUE                VARCHAR2(20);

Begin
            SELECT LENGTH(FAMILY) INTO V_LENGTH FROM SUBSCRIPTION_TEST WHERE ACCOUNT_NO='84121262';

  For i in 1..V_LENGTH 
      Loop
                      V_position := 0;
                      select  REGEXP_REPLACE(INSTR (FAMILY, '1', 1, i),'0','') into V_position from SUBSCRIPTION_TEST WHERE ACCOUNT_NO='84121262';
                      dbms_output.put_line(V_POSITION );
                      V_VALUE:=TO_CHAR(ADD_MONTHS(SYSDATE,-V_POSITION),'YYYYMM');
                      DBMS_OUTPUT.PUT_LINE(V_VALUE);  
      End Loop;
END;
my output as below:
201103
1
201102
2
201009
*1*--------------------------------10 position
*201103*------------------------------201006
11
201004
i m getg the out put as above because of replace function used in my code .can you please solve this issue .

my output should be as below
201103
1
201102
2
201009
10
201006
11
201004

Edited by: 841719 on Mar 15, 2011 3:54 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 12 2011
Added on Mar 15 2011
2 comments
304 views