SQL Query [message #587204] |
Thu, 13 June 2013 04:02  |
 |
userora
Messages: 63 Registered: December 2012 Location: Chennai
|
Member |
|
|
Hi All,
Please can any one help me to frame a query for the below values . Thanks in Advance.
I have few records in a below format.
1) 'CODE#ATC#YEAR#1980#NUM#4229#VOL#80##'
2) 'CODE#NSWLR#YEAR#1985#PAGE#158#VOL#4##'
3) 'CODE#WASC#YEAR#1981#MONTH#07#DAY#24#'
4) 'CODE#RPC#YEAR#1919#PAGE#296#VOL#36#'
I need only the Page from the above records.
For example if i take this record
'CODE#NSWLR#YEAR#1985#PAGE#158#VOL#4##' -- I need to extract only the Page from this like 158.
If the record doesn't contain Page then i need to update as null.
|
|
|
|
|
|
|
|
Re: SQL Query [message #587217 is a reply to message #587214] |
Thu, 13 June 2013 04:32   |
cookiemonster
Messages: 13968 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
So why have you put the 2nd parameter to substr as 1? You don't want the first several characters in the string do you?
And I'd be telling instr to look for 'PAGE' not '#'
|
|
|
|
|
|
|
|
|
Re: SQL Query [message #587262 is a reply to message #587231] |
Thu, 13 June 2013 09:36   |
Solomon Yakobson
Messages: 3305 Registered: January 2010 Location: Connecticut, USA
|
Senior Member |
|
|
Littlefoot wrote on Thu, 13 June 2013 07:03or something else.
On 11g REGEXP_SUBSTR supports sub-expressions, so replace is not needed:
with t as (
select 'CODE#MacG Cop Cas#YEAR#1923-28#PAGE#34-0#' ,'CODE#MacG Cop Cas#YEAR#1923-28#PAGE#340a#' column_name
from dual
)
select regexp_substr(column_name, 'PAGE#(\d+)',1,1,null,1)
from t
/
REG
---
340
SQL>
SY.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: SQL Query [message #587434 is a reply to message #587278] |
Fri, 14 June 2013 14:55   |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
6 guys trying to help the poster, 3 are posting hints with examples, other 3 are asking to follow forum guidelines, lest the poster shouldn't be helped. Who is confusing whom? Why not be clear at the 1st step.
|
|
|
Re: SQL Query [message #587436 is a reply to message #587434] |
Fri, 14 June 2013 15:14   |
pablolee
Messages: 2882 Registered: May 2007 Location: Scotland
|
Senior Member |
|
|
Lalit Kumar B wrote on Fri, 14 June 2013 20:556 guys trying to help the poster, 3 are posting hints with examples, other 3 are asking to follow forum guidelines, I disagree.
Quote:lest the poster shouldn't be helped. Who is confusing whom? Exactly what point are you attempting to make here?
Quote:Why not be clear at the 1st step.
What part of cookie's first post do you find unclear?
[Updated on: Fri, 14 June 2013 15:14] Report message to a moderator
|
|
|
|
Re: SQL Query [message #587440 is a reply to message #587436] |
Fri, 14 June 2013 15:29   |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
BlackSwan posted forum guidelines almost after a lot of replies, however, the poster repeatedly did not follow. Had it been very clear in the beginning itself, then no point of so much of effort. I appreciate the effort that was made to help the poster.
But, look in the end, the poster simply left the thread without even caring to tell what she learnt or how she fixed the issue that she faced earlier.It must be a win-win situation, where the helper should be satisfied in the end that the poster completely understood what was being explained.
|
|
|
Re: SQL Query [message #587443 is a reply to message #587440] |
Fri, 14 June 2013 15:38  |
pablolee
Messages: 2882 Registered: May 2007 Location: Scotland
|
Senior Member |
|
|
Lalit Kumar B wrote on Fri, 14 June 2013 21:29BlackSwan posted forum guidelines almost after a lot of replies, OK, that's one person. You said three posted guidelines. I disagree.
Quote:however, the poster repeatedly did not follow. Correct, very rude.
Quote: Had it been very clear in the beginning itself, then no point of so much of effort. Had what been clear? The question? The first answer? The request for the OP to follow some very simple guidelines?
Quote:I appreciate the effort that was made to help the poster. You have no idea how happy that makes me, my heart is filled with joy and my life full of light with that knowledge.
Quote:But, look in the end, the poster simply left the thread without even caring to tell what she learnt Yes, very, very rude of her.
Quote:or how she fixed the issue that she faced earlier. If indeed, she actually did fix it.
Quote:It must be a win-win situation, where the helper should be satisfied in the end that the poster completely understood what was being explained. Then the first step would be for people to follow the rules don't you think?
[Updated on: Fri, 14 June 2013 15:39] Report message to a moderator
|
|
|