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.
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.
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.
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.
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.
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.
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? 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.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With