cancel
Showing results for 
Search instead for 
Did you mean: 

How can I select the third digit of a string?

former_member786463
Discoverer
0 Kudos
385

Hi!

I need your help!

How can I select only the third digit of a docnum string?

for instance:

if I have a DocNum 22101

I would like to select only the third digit, in this case 1.

Thanks in advance for the help.

moshenaveh
Community Manager
Community Manager
0 Kudos

Welcome and thanks for visiting SAP Community to get answers to your questions. While you're waiting for help, check out our tutorial to get started in SAP Community: https://developers.sap.com/tutorials/community-qa.html, as it provides tips for preparing questions that draw responses from our members. For example, you can: - outline what steps you took to find answers (and why they weren't helpful) - share screenshots of what you've seen/done - make sure you've applied the appropriate tags The more details you provide, the more likely it is that members will be able to help you. Should you wish, you can revise your question by selecting Actions, then Edit. By adding a picture to your profile you encourage readers to respond to your question. Learn more about your profile here: https://developers.sap.com/tutorials/community-profile.html

chris_keating
Product and Topic Expert
Product and Topic Expert
0 Kudos

If the format consistently "<some_str> <some_set_nums>"?

If so, the following will work:

create or replace table r(
id integer,
c char(20) );
insert into r values ( 1, 'DocNum 12345' );
commit;
select substr( REGEXP_SUBSTR( c, '[[:digit:]]{3}' ), 3 ) as The3rdDigit from r;

If the format is more variable, you should still be able to construct a solution using a REGEXP_SUBSTR.

See Regular Expressions Overview - SAP Help Portal

Accepted Solutions (0)

Answers (0)