By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
REGEXP_SUBSTR('ABCDEFG#3H#IJKL12MKA#123456#L#5','[^#]+',1,4) |
---|
123456 |
REGEXP_SUBSTR('ABCDEFGHIJKL#3HWEFSS#IJKL12MKASFDS#123456#L1111#511111','[^#]+',1,4) |
---|
123456 |