GolezTrol's response extension allows the use of regular expressions to significantly reduce the number of recursive queries:
select instr('SSSRNNSRSSR','R', 1, level) from dual connect by level <= regexp_count('SSSRNNSRSSR', 'R')
REGEXP_COUNT () returns the number of matches of the pattern, in which case the number R exists in SSSRNNSRSSR . This limits the recursion level to the exact number you need.
INSTR () just looks for the index R in your string. level is the depth of the recursion, but in this case it is also the th level of the string entry, since we limited the number of recursions required.
If the line you want to select is harder, you can use the regular expressions ans REGEXP_INSTR () as opposed to INSTR (), but it will be slower (not much), and this is optional unless required.
Simple criteria on request:
Two CONNECT BY solutions indicate that using REGEXP_COUNT is 20% faster on a row of this size.
SQL> set timing on SQL> SQL> -- CONNECT BY with REGEX SQL> declare 2 type t__num is table of number index by binary_integer; 3 t_num t__num; 4 begin 5 for i in 1 .. 100000 loop 6 select instr('SSSRNNSRSSR','R', 1, level) 7 bulk collect into t_num 8 from dual 9 connect by level <= regexp_count('SSSRNNSRSSR', 'R') 10 ; 11 end loop; 12 end; 13 / PL/SQL procedure successfully completed. Elapsed: 00:00:03.94 SQL> SQL> -- CONNECT BY with filter SQL> declare 2 type t__num is table of number index by binary_integer; 3 t_num t__num; 4 begin 5 for i in 1 .. 100000 loop 6 select pos 7 bulk collect into t_num 8 from ( select substr('SSSRNNSRSSR', level, 1) as character 9 , level as pos 10 from dual t 11 connect by level <= length('SSSRNNSRSSR') ) 12 where character = 'R' 13 ; 14 end loop; 15 end; 16 / PL/SQL procedure successfully completed. Elapsed: 00:00:04.80
The pipeline table function works more slowly, although it would be interesting to see how it runs on large rows with a lot of matches.
SQL> -- PIPELINED TABLE FUNCTION SQL> declare 2 type t__num is table of number index by binary_integer; 3 t_num t__num; 4 begin 5 for i in 1 .. 100000 loop 6 select * 7 bulk collect into t_num 8 from table(string_indexes('SSSRNNSRSSR','R')) 9 ; 10 end loop; 11 end; 12 / PL/SQL procedure successfully completed. Elapsed: 00:00:06.54