last day (15 days later) » 

3:39 AM
0
A: USING SQL . extract numbers comma separated from string 'HEADER|N1000|E1001|N1002|E1003|N1004|N1005'

NickOne way to achieve your desired result is to replace a string of characters leading up to a number with that number and a comma, and then replace any characters from the last ,| to the end of string from the result: SELECT REGEXP_REPLACE(REGEXP_REPLACE('HEADER|N1000|E1001|N1002|E1003|N1004|N1005...

 
error - it shows From keyword not found where expected
and thanks for answering . can u point out why it is showing error
 
@amarenderreddyjali you can just add FROM dual to the end of the queries
 
Meta Stack Overflow SELECT REGEXP_REPLACE('HEADER|N1000|E1001|N1002|E1003|N1004|N1005|'‌​, '.*?(\\d+)', '\\1,')) is not exactly replacing characters leading up to a number . it is just giving the same string as result
 
@amarenderreddyjali You can see that the demo works, for MariaDB. What DBMS are you using? I will update my demo for it.
 
can u check the regexp expression it is just giving the same string as result
sybase . i am running it in oracle sql developer
 
3:39 AM
@amarenderreddyjali I have updated my answer and demo for Oracle
 
oracle database . . i am running it on oracle sql developer. thanks will check and tell
 
@amarenderreddyjali please see my edited answer. It should work for you now.
 
thank u so much nick i really appreciate ur help. thanks can u also recommend me some study links so i can learn this stuff
 
@amarenderreddyjali no worries - I'm glad I could help. In terms of learning, this might help: stackoverflow.com/questions/4736/learning-regular-expression‌​s
 
hi for the output of numbers beginning with E, SELECT TRIM(',' FROM TRIM('|' FROM REGEXP_REPLACE('HEADER|N1000|E1001|N1002|E1003|N1004|N1005|'‌​, '.*?E(\d+)', '\1,'))) FROM dual it is showing wrong output
 
3:39 AM
@amarenderreddyjali Please see my edited answer and updated demo. I didn't allow for a number not being the last item in the string, the new query does that.
 
Thank you so much. u removed trim . if possible and if u are free ! take ur time can u briefly say what first regexp_replace and inner regexp are doing. no hurries. thanks u so much . this was my first time in stack overflow and my first question i didnt expect some one to answer my question . thanks fo all ur time on this question
 
@amarenderreddyjali no worries - the inner replace is replacing all characters up to a string of digits (preceded by an N or an E in the second and third examples) by the string of digits followed by a comma. This gives a string that looks like e.g. 1001,1003,|N1004|N1005 for the third example, and the outer replace removes everything from the ,| to the end of the string (it's a more sophisticated version of what the TRIM was doing)
 
are u there nick .plzzz help me here . yesterday solution . the input correction it doesnt have '|' pipe symbol at last so . i thought removing pipe symbol in your query might work . it was working for this particular data set but when i input 'HEADER|N1000|E1001|N1002|E1003' it gives wrong answer
 
@amarenderreddyjali change to SELECT REGEXP_REPLACE(REGEXP_REPLACE('HEADER|N1000|E1001|N1002|E100‌​3', '.*?E(\d+)', '\1,'), ',(\|.*)?$', '') FROM dual instead. dbfiddle.uk/…
 
FOR different input it is failing like if only N numbers are there in the input SELECT REGEXP_REPLACE(REGEXP_REPLACE('HEADER|N1000|N1001|N1002|N100‌​3', '.*?E(\d+)', '\1,'), ',(\|.*)?$', '') FROM dual
 
3:39 AM
@amarenderreddyjali you keep moving the goalposts... it's not reasonable to ask a question with one data format and then keep changing it. It's late here, I'll take a look in the morning. If you can't wait, ask a new question and refer back to this one.
 
please please . i am unable to ask a new question for 1 more day . can u just look into it for 5 mins i think u can do it . it just that data sets of containing only N numbers or E numbers it is failing can u look into this.
i see that ur a australian ok time difference got it . thanks for replying at 10 :30 in night and let me clarify the whole scenerio <br/> 1) the data set doesn't have pipe at the end <br/> 2) dataset may have only e numbers or n numbers . *when it only has n numbers but i am searching for e numbers it is throwing error *. so thanks for helping upto this point . please help in solution
sorry, this is my first question in stack exchange . so i didnt gave all the data properly. i should have specified that the solution should not be data set specific and it should take this kind of alternate data set scenerios . my bad . i am sorry for constantly bugging you
 
@amarenderreddyjali please update the question with all the possible data sets and I will take a look at it later today
 
3:58 AM
@nick i have added other possible datasets in the question
 
 
3 hours later…
7:00 AM
@nick
are u there
 
 
3 hours later…
10:20 AM
NICK
@NICK
PLZZ RESPOND
I HAVE
A REQUEST
SELECT REGEXP_REPLACE(REGEXP_REPLACE('HEADER|N1000|E1001|N1002|E100‌​3', '.*?E(\d+)', '\1,'), ',(\|.*)?$', '')
SEE THIS IS UR OLDER SOLUTION
 

last day (15 days later) »