Extract numbers from mixed string.
How do I extract numbers from a mixed-character string?
These are house numbers and I have some exceptions - examples below.
How do I get rid of the letter/dash part, and keep the numeric part only?
38A
5600B
23-A
Thanks a lot.
-John
It does not work if you have a string like 3343S##@1~!234
OP, you can try this:
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
SQL> with t as(
2 select '38A' c1 from dual union all
3 select '5600B' from dual union all
4 select '5Bas@#$%1SDf3ff`~7' from dual union all
5 select '3343S##@1~!234' from dual union all
6 select '23-A+9' from dual )
7 --
8 select c1,regexp_replace(c1,'[^[:digit:]]') only_num from t;
C1 ONLY_NUM
38A 38
5600B 5600
5Bas@#$%1SDf3ff`~7 5137
3343S##@1~!234 33431234
23-A+9 239
SQL>
Similar Messages
-
Hi,
I am curious if there is an easy way to extract an int value from a String.
For example, "Rb23" to get 23. The length of the part in front of the integer is variable.
Thanksthis seems to work:
public int extract(String s) {
String result = "";
char c[] = s.toCharArray();
int j = c.length-1;
if (!Character.isDigit(c[j])) {
return 0;
do {
result+=c[j--];
} while (j > 0 && Character.isDigit(c[j]));
return Integer.parseInt(new StringBuffer(result).reverse().toString());
}it will return 0 if no numbers are found at the end of the string -
Hi guys,
I have a column that contains Names with Mobile numbers. How can I get rid off the letters in the column, or how can I extract only the numbers from the column!!!!
Best Regards,Or you can use REAPLCE and TRANSLATE functions if your DB versio is lower than 10g
SELECT REPLACE(TRANSLATE(UPPER('ArunKumarGupta9000888777'),'ABCDEFGHIJKLMNOPQRSTUVWXYZ',' '),' ','')
FROM DUALRegards
Arun -
Extracting data from a string of characters
Hi,
I have a problem that I am having difficulty solving, if anyone has any bright ideas it would be a great help.
I have a description field in one of my tables and the description would read something like
my website can be found at www.mywebsite.com, and it is great
I want to be able to extract the web address from this sentance, so the result would be
www.mywebsite.com
I can do this specific for one sentance but I can't find a way to do it for many different sentances.
cheers in advanceIf you're using 10g, you probably want to do something with regular expressions:
SQL> with strings as (
2 select
3 'my website can be found at www.mywebsite.com, and it is great' str
4 from
5 dual
6 union all
7 select
8 'my website can be found at WWW.myWebSite.com, and it is great'
9 from
10 dual
11 union all
12 select
13 'our web address is www.mywebsite.co.uk' str
14 from
15 dual
16 union all
17 select
18 'http://www.mywebsite.com/great'
19 from
20 dual)
21 select
22 s.str
23 , regexp_substr(s.str, 'www\.[a-z0-9-\.?]*', 1, 1, 'i') extr
24 from
25 strings s
26 /
STR EXTR
my website can be found at www.mywebsite.com, and it is great www.mywebsite.com
my website can be found at WWW.myWebSite.com, and it is great WWW.myWebSite.com
our web address is www.mywebsite.co.uk www.mywebsite.co.uk
http://www.mywebsite.com/great www.mywebsite.comYou'd be better asking this kind of thing on the PL/SQL (and definitely better asking someone other than me anything further about regular expressions!) -
select * from v$version;
BANNER
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
PL/SQL Release 11.1.0.7.0 - Production
CORE 11.1.0.7.0 Production
TNS for Linux: Version 11.1.0.7.0 - Production
NLSRTL Version 11.1.0.7.0 - ProductionI want to extract xyz_xyz,abc_abc words from the string ' select * from TEMP_TABLE where trunc(xyz_xyz) = ''xyz'' and trunc(abc_abc) = ''abc'') '
i have tried with this query...
select regexp_substr('select * from TEMP_TABLE where trunc(xyz_xyz) = ''xyz'' and trunc(abc_abc) = ''abc'')', 'trunc[^'''']+''') from dual
can some one help me on this?
Thanks,
MikeHi, Mike,
Mike wrote:
I apologize for this..
create table TEMP_TABLE ( col1 varchar2(10),col2 varchar2(10));
insert into TEMP_TABLE values(' xyz ','abc ');
insert into TEMP_TABLE values(' xyzxyz ','abcabc ');
insert into TEMP_TABLE values(' xyz123 ','abc546 ');
insert into TEMP_TABLE values('xyz','abc');
commit
select * from TEMP_TABLE where trim(col1) ='xyz' and trim(col2) ='abc'
desired output
col1,col2
So the correct output is one row, containing these 9 characters
col1,col2which do not appear in the table. is that right?
How is that output related to the data that is in the table? Do you want that output to appear if there are any rows where TRIM (col1) = 'xyz' and TRIM (col2) = 'abc' (for example, either of these two rows from you sample data:
insert into TEMP_TABLE values(' xyz ','abc ');
insert into TEMP_TABLE values('xyz','abc');), and would you want the result set to contain no rows if the table contained no row like that?
If so,
SELECT DISTINCT
'col1,col2' AS desired_output
FROM temp_table
WHERE TRIM (col1) = 'xyz'
AND TRIM (col2) = 'abc'
;I hope this answers your question.
I have a feeling that it doesn't, or perhaps you have more than one question, since this your earlier messages seemed to have something to do with locating text that was surrounded by single-quotes, and the sample data you posted doesn't contain any single-quotes. -
Help: how to extract digits from a string?
Hi,
I am trying to make a formatted phone number report. The field is VARCHAR2(20). There might be some sort of irregularities. What I need to do are in two steps:
1. extract all digits in order;
2. format the output as (xxx) xxx-xxxx
Any suggestions?
Thank you in advance.
JimmyThis might be of some use to clean up the phone numbers.
drop table phone_numbers;
create table phone_numbers
(phone varchar2(20));
insert into phone_numbers(phone) values ('(111)-555-1212');
insert into phone_numbers(phone) values (' 111 555 1212');
insert into phone_numbers(phone) values ('#555-1212');
insert into phone_numbers(phone) values ('Bob @ 555-1212');
commit;
select phone, translate(phone,'0123456789()-.@#* ','0123456789') edited_phone
from phone_numbers;
PHONE EDITED_PHONE
(111)-555-1212 1115551212
111 555 1212 1115551212
#555-1212 5551212
Bob @ 555-1212 Bob5551212You can see by the last example that the search string in the translate function should contain every character you can type on a keyboard. -
How can I get the last 18 numbers from this string
Hi,
I'm querying this field from a table. How can I only get the last 18 numbers:
The numbers look like this:
500000000818118If it is always the last 18 numbers just use the Right() function. Examples:
Right("500000000818118", 18)
or
<cfset mystring = "500000000818118">
<cfset mynewstring = Right(mystring, 18)>
or
#Right(yourquerycolumn, 18)#
etc.
Edit:
Well I just noticed that your example string is only 15 characters long. Perhaps I mis-understood your question?
Message was edited by: Miguel-F -
Extract number from long string
I have this ugly string in a column of type VARCHAR2. 34382-172.28.129.212(88:6c:de:32:51:a5)-38065-1279731239826
Is there a way to parse this string into a number (remove all letters and punctuation) when selecting from the db? Thanks for any suggestionsI wasn't sure if I got your requirements right so I wrote a statement with several solutions, in any case if you're using Version 10g or higher, regular expressions are your friends:
WITH t as (SELECT '34382-172.28.129.212(88:6c:de:32:51:a5)-38065-1279731239826' col1
FROM dual
SELECT t.col1
-- solution 1: only the first number
, REGEXP_SUBSTR(t.col1, '^\d+') solution_1
-- solution 2: all numbers (without the IP/Mac-Address)
, REGEXP_REPLACE(t.col1, '((^\d+)-|(-\d+))|.','\2\3') solution_2
-- solution 3: all digits
, REGEXP_REPLACE(t.col1, '\D') solution_3
FROM t
COL1 SOLUTION_1 SOLUTION_2 SOLUTION_3
34382-172.28.129.212(88:6c:de:32:51:a5)-38065-1279731239826 34382 34382-38065-1279731239826 343821722812921288632515380651279731239826 C. -
How to extract substring from a string based on the condition ??
Hi,
I'm having a very large string which as below
EQD+CN+SAMPLE18767+2200+++5'
NAD+CA+FIR:172:20'
DGS+IMD+3.2+2346+55:CEL'
FTX+AAA+++GOOD'
FTX+AAA+++ONE'
EQD+CN+SAMPLE18795+2200+++5'
NAD+CA+TIR:172:20'
DGS+IMD+3.2+2346+55:CEL'
FTX+AAA+++SECOND'
FTX+AAA+++IS FAIR'
similarly FTX+AAA as above and it goes on
i tokenized each segment with delimiter as ' and able to read each segment.
Now i want to concatenate the FTX+AAA in a single segment if more than one FTX+AAA with IMMEDIATE below
The output is as follows
EQD+CN+SAMPLE18767+2200+++5'
NAD+CA+FIR:172:20'
DGS+IMD+3.2+2346+55:CEL'
FTX+AAA+++GOOD,ONE'
EQD+CN+SAMPLE18795+2200+++5'
NAD+CA+TIR:172:20'
DGS+IMD+3.2+2346+55:CEL'
FTX+AAA+++SECOND,IS FAIR'
similarly FTX+AAA should be concatenated if it has similar FTX+AAA IMMEDIATE below.
The FTX+AAA segments can come any number of times immediate below
Please help me how we can do this??? Can anyone help me with the code snippet to do this?
Thanks,
KathirEncephalopathic wrote:
You've posted > 300 times here and you still don't respect the rule regarding notification of all cross-posts? [http://www.java-forums.org/advanced-java/30061-how-extract-substring-string-based-condition.html]
Do you think this this will help convince others to help you?See also [http://www.coderanch.com/t/500088/java/java/extract-substring-string-based-condition|http://www.coderanch.com/t/500088/java/java/extract-substring-string-based-condition]. -
How do I extract doubles from a string??
If I have an array of string such as ("4.5 6.2 4.2"). Each array element has either 1, 2 or 3 numbers but they are all in the string format.
I'm looking for advice on how to segment out and then wrap each double.
Any suggestions??If I have an array of string such as ("4.5 6.2 4.2").
Each array element has either 1, 2 or 3 numbers but
they are all in the string format.
String str = "4.5 6.2 4.2";
StringTokenizer tkn = new StringTokenizer(str, " ");
double doub = new double[tkn.countTokens()];
int j=0;
while(tkn.hasMoreTokens() ){
doub[j]= Double.parseDouble(tkn.nextToken() );
I'm looking for advice on how to segment out and then
wrap each double.Good idea
Any suggestions??Yep! -
Extract date from text string - Transact-SQL
Hello,
I have a field in my database with an archived date... (Giampaoli Live Oak, Almonds Archive 09/16/10)
I need to be able to extract the date from this, then perform a datepart function on it... How do I extract the date into it's own value using just SQL?
Thanks,
WesThanks Guys,
This helped me:
select
ID,
NAME,
datepart(month, CONVERT(date, SUBSTRING(YOUR_COLUMN_NAME, patindex('%[0-9][0-9]/[0-9][0-9]/[0-9][0-9]%', YOUR_COLUMN_NAME), 50))) AS MONTHARCHIVED,
datepart(YEAR, CONVERT(date, SUBSTRING(YOUR_COLUMN_NAME, patindex('%[0-9][0-9]/[0-9][0-9]/[0-9][0-9]%', YOUR_COLUMN_NAME), 50))) AS YEAR_ARCHIVED
FROM
TABLEABC
Thanks Shiven:) If Answer is Helpful, Please Vote -
I want to read lines from file, count it and extract numbers from a first line.
i must do un loop?
HI,
i try to explain how to use to LABVIEW TOOLS...
1. USE a for next loop
2. here you must open the file with the VI. read lines from file.
you can choos how many lines you read at same time.
3. the string you can convert into an number.
4. in the loop is the literal counter... this is you line couter....
iun schrieb:
> i must do un loop? -
How can I extract text from a string
Hello,
I have a name column that has both first name and last name joined together as a string. I want to separate them in two different columns as firstname and lastname.
I use Report builder, please help with the query that will separate the string into two diferent columns.
ThanksHi sanjb12001,
Per my understanding that you want to separate a name column which contain the information of "First Name", "Middle Name", "Last Name" into three different column, right?
I have tested on my local environment and we have method to do this, one is do this in the query and Patrick Hurst
have already provide the solution, another method is to create three calculated fields using the split function in the expression to get the three new columns.
I assume you have the format like this in the name fields "FirstName MiddleName LastName", Details information about create the three columns for your reference:
Right click the dataset and select the "Add Calculated Field" to add three fields "FirstName", "MiddleName", "LastName":
Using below expression to get the values for these fields:
FirstName:
=split(Fields!name.Value," ")(0)
MiddleName:
=IIF(split(Fields!name.Value," ").Length=3,split(Fields!name.Value," ")(1),"")
LastName:
=split(Fields!name.Value," ")(split(Fields!name.Value," ").Length-1)
Preview you will got the result:
If you still have any problem, please feel free to ask.
Regards
Vicky Liu -
More efficient way to extract number from string
Hello guys,
I am using this Regexp to extract numbers from a string, and I doubt that there is a more efficient way to get this done:
SELECT regexp_replace (regexp_replace ( REGEXp_REPLACE (' !@#$%^&*()_+= '' + 00 SDFKA 324 000 8702 234 | " ' , '[[:punct:]]',''), '[[:space:]]',''), '[[:alpha:]]','') FROM dual
{code}
Is there a more efficient way to get this done ?
Regards,
FatehOr, with less writing, using Perl syntax \D (non-digit):
SELECT regexp_replace(' !@#$%^&*()_+= '' + 00 SDFKA 324 000 8702 234 | " ','\D')
FROM dual
REGEXP_REPLACE(
003240008702234
SQL>
{code}
SY. -
Extract date from string in T-SQL
Hi,
I am having one field(AT_TEXT) in my database that has below kind of values. I want to extract date from this string but the issue is all rows has different format.
1)One Month Lttr sent on 3/12/2009 due to
2)One Month Letter sent on 1/15/2009 due to
3)One Month letter sent on7/15/2011.The amount due - This has no space between on and 7 and . after yr
4)One Month letter sent on 7/16/12 due to - This has 12 instead of 2012(2 positions after 2nd slash/)
Can anyone please help me to write query to extract date from this string?
VickyHi Jingyang
Li,
I checked your query and it looks good but I have one issue. So when we reverse it, it looks like below and it is talking that $57.80 as a 1st numeric value and try to convert it into date and giving me error.
I realize from your query that you are trying to reverse the value and then try to find out 1st Numeric value from that string, but my whole string has another numeric value at the end, like
"One Month Letter on 1/15/2009 due to non-pmt of prems-amt to avoid DE is $57.80"
So when we reverse it, it looks like below and it is taking that $57.80 as a 1st numeric value and try to convert it into date and giving me error.
"08.75$ si ED diova ot eud tma - smerp fo tmp-non ot eud 9002/51/1 no retteL htnoM enO"
Also sometimes I have $ amount at the end and sometimes I don't have any $ amount at the end, like below,
"One Month letter sent on 10/15/2012 due to non-payment of premiums. The amount due to avoid dise"
Can you please modify your query which takes only date part not the $ amount and give me?
Thank you so much for your help
Vicky
Maybe you are looking for
-
Multiple iPhoto libraries when I click on the iPhoto icon in the dock.
I see four iPhoto libraries when I right click on the iPhoto icon in the Dock, but I only actually have two libraries. The other two simply do not exist on my computer. And when I click on the libraries that do not exist, obviously nothing happens.
-
Pressing enter instead of clicking on a button
Hey all, this is rather simple but the search term 'enter' is very common so i'm having a hard time searching for my solution! I'm basically writing a search program that finds customers, at the moment I have a screen where the user types in a name t
-
Printing List Boxes w/no fill
The following was posted by someone in 2008 with no resolution...I am having the same problem now...any help is greatly appreciated! "I have a problem with the fill color/shading of dropdown boxes. I have created several forms that include dropdown o
-
Problems gifting playlist - order randomized and Error 1008
I can purchase music fine, so I know my account is indeed working. But when I try to gift a playlist via the iTunes Store, 2 errors keep occuring: 1. Track order gets randomized. (Not that it'd matter, but I don't have shuffle checked.) Each time I t
-
Using multicolumn listbox as indicator
I am trying to have data that I am collecting display on a multicolumn as it comes in. I don't know if you can do this and if you can I dont know how I can control where the data goes on the listbox. So can anyone explain this please? Thanks Solved!