473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Extract the beginning of a string

Hi,

I have a column containing a string; the string always starts with a
letter (a-z), followed by an undefined number of letters, then one
number or more.

The REGEXP would look like [a-zA-Z][a-zA-Z]*[0-9]+

I need to extract the letters at the beginning in an SQL query or in
PL/SQL

For example, If I have

abc123 -> abc

a123 -> a

abcdefgh1 -> abcdefgh

Any suggestion ?
Thank you

Bernard Drolet
Jul 19 '05 #1
3 6526
VC
Hello Bernard,

You can do it so:

select translate('xyz174',

'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw xyz0123456789',
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw xyz')
from dual;

Rgds.

"Bernard Drolet" <le****@yahoo.ca> wrote in message
news:ee**************************@posting.google.c om...
Hi,

I have a column containing a string; the string always starts with a
letter (a-z), followed by an undefined number of letters, then one
number or more.

The REGEXP would look like [a-zA-Z][a-zA-Z]*[0-9]+

I need to extract the letters at the beginning in an SQL query or in
PL/SQL

For example, If I have

abc123 -> abc

a123 -> a

abcdefgh1 -> abcdefgh

Any suggestion ?
Thank you

Bernard Drolet

Jul 19 '05 #2
or, if the last portion is all numeric

rtrim( theString, '0123456789')

or if, the last portion is not all numeric

substr(
theString
,1
,instr(
translate(
theString
,'0123456789'
,'0000000000'
)
, '0'
) -1
)

translate replaces all digits with '0'
instr finds the position of the first '0'
this decremented and used as the length for substr

if the numeric part is optional, you'll need to add a decode to check for an
instr value of 0

whatever you do, consider creating a stored function rather than putting
this expression directly into your SQL statement

--
Mark C. Stock
email mcstock -> enquery(dot)com
www.enquery.com
(888) 512-2048
"VC" <bo*******@hotmail.com> wrote in message
news:_RAqb.131051$HS4.1031371@attbi_s01...
Hello Bernard,

You can do it so:

select translate('xyz174',

'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw xyz0123456789',
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw xyz')
from dual;

Rgds.

"Bernard Drolet" <le****@yahoo.ca> wrote in message
news:ee**************************@posting.google.c om...
Hi,

I have a column containing a string; the string always starts with a
letter (a-z), followed by an undefined number of letters, then one
number or more.

The REGEXP would look like [a-zA-Z][a-zA-Z]*[0-9]+

I need to extract the letters at the beginning in an SQL query or in
PL/SQL

For example, If I have

abc123 -> abc

a123 -> a

abcdefgh1 -> abcdefgh

Any suggestion ?
Thank you

Bernard Drolet


Jul 19 '05 #3
"mcstock" <mc*************@spamdamenquery.com> wrote in message news:<h9********************@comcast.com>...
or, if the last portion is all numeric

rtrim( theString, '0123456789')

or if, the last portion is not all numeric

substr(
theString
,1
,instr(
translate(
theString
,'0123456789'
,'0000000000'
)
, '0'
) -1
)

translate replaces all digits with '0'
instr finds the position of the first '0'
this decremented and used as the length for substr

if the numeric part is optional, you'll need to add a decode to check for an
instr value of 0

whatever you do, consider creating a stored function rather than putting
this expression directly into your SQL statement

--
Mark C. Stock
email mcstock -> enquery(dot)com
www.enquery.com
(888) 512-2048

Hi Mark, you guessed right,

my string contains more than just text;
a real example would like as 'AMM05-10-00-210-801-A01';
your solution worked perfectly.
Thank you

Bernard Drolet

PS: I implemented it in a function, as suggested ;-)
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Tim Smith | last post by:
I am looking to extract form element values from html, more generally I have a substring that identifies the beginning of a value and a string that identifies the end of value and I need to extract...
10
by: Robert Schultz | last post by:
I have a C/C++ file that I simply want to 'extract' a function from. Something like: extract <function name> <c or cpp file> I want it to return from the beginning of the function, to the end. ...
8
by: Amit Khemka | last post by:
Hello All, say you have some string: ", foobar " Now i want to extract all substrings for which "isinstance(eval(substr), list)" is "True" . now one way is to walk through the whole sample...
8
by: nick | last post by:
Hi all can any one please tell me what is wrong in this code?? I'm new to deal with text files and extract data. i'm trying to look for data in a text file (3~4 pages) some lines start with a...
2
by: teo | last post by:
I have a problem (partial). Some days ago I asked for a way to extract a word and few text around it (30 chars on the left and 30 on the right) from a long text. I went good with: ...
9
by: flit | last post by:
Hello All, Using poplib in python I can extract only the headers using the .top, there is a way to extract only the message text without the headers? like remove the fields below: "...
34
by: Umesh | last post by:
I want to extract a string abc*xyz from a text file. * indicates arbitrary no. of characters. I'm only able to do it when the string has definite no. of characters or the string length is...
1
by: Alberto Sartori | last post by:
Hello, I have a html text with custom tags which looks like html comment, such: "text text text <p>text</ptext test test text text text <p>text</ptext test test <!-- @MyTag@ -->extract...
3
by: Bernard Drolet | last post by:
Hi, I have a column containing a string; the string always starts with a letter (a-z), followed by an undefined number of letters, then one number or more. The REGEXP would look like *+ I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.