Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle extract alpha characters from string

I want to extract only alpha characters separately.
For example Output for "NIC132DA.1" should be "NIC" and "DA" separately without any numbers.
I tried following query:

select regexp_replace('NIC132DA.1','[^A-Za-z]') from dual;

I get following output: NICDA
Expected out put is "NIC" and "DA" separately.
Note: Number of alpha characters are not fixed in input string.

like image 734
imsome1 Avatar asked Feb 09 '17 09:02

imsome1


People also ask

How do you find a specific character in a string in Oracle?

The Oracle INSTR function is used to search string for substring and find the location of the substring in the string. If a substring that is equal to substring is found, then the function returns an integer indicating the position of the first character of this substring.

How do you check alphanumeric in PL SQL?

Answer: To test a string for alphanumeric characters, you could use a combination of the LENGTH function, TRIM function, and TRANSLATE function built into Oracle. The string value that you are testing. This function will return a null value if string1 is alphanumeric.

What is the use of Regexp_substr in Oracle?

REGEXP_SUBSTR extends the functionality of the SUBSTR function by letting you search a string for a regular expression pattern. It is also similar to REGEXP_INSTR , but instead of returning the position of the substring, it returns the substring itself.

How to extract a substring from a string in Oracle?

The Oracle SUBSTR () function extracts a substring from a string with various flexible options. The following illustrates the syntax of the Oracle SUBSTR () function: str is the string that you want to extract the substring.

How to extract numbers and alphabets from a string?

Description Extract numbers and alphabets from a string. Select using regexp_substr pattern matching for the first occurrence of a number, a number followed by a string of characters, and a specific letter followed by a pattern of letters and numbers string.

How do I test a string for alphabetic characters in Oracle?

Answer: To test a string for alphabetic characters, you could use a combination of the LENGTH function, TRIM function, and TRANSLATE function built into Oracle. This function will return a null value if string1 is alphabetic.

What is an oracle extract () function?

What is an Oracle EXTRACT () Function? An Oracle EXTRACTFunction is used to extract components from the given input, as EXTRACT function name suggests. It extracts and returns a specified date-time value or interval value. It returns a string containing the appropriate time zone name or abbreviation if we extract it.


Video Answer


1 Answers

You can use REGEXP_SUBSTR:

select 
    regexp_substr('NIC132DA.1','[A-Za-z]+', 1, 1) first,
    regexp_substr('NIC132DA.1','[A-Za-z]+', 1, 2) second
from dual;

It's better to use multilingual character class [:alpha:]:

select 
    regexp_substr('NIC132DA.1','[[:alpha:]]+', 1, 1) first,
    regexp_substr('NIC132DA.1','[[:alpha:]]+', 1, 2) second
from dual;
like image 139
Gurwinder Singh Avatar answered Oct 11 '22 00:10

Gurwinder Singh