Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular expression Oracle

I am learning to use regular expressions and I'm using them to limit the results of a search query by using the REGEXP_LIKE in Oracle 11. Placing an example of the data available, I have the following:

Plan navegación 200 MB
Plan navegación 1 GB
Plan navegación 1 GB
Plan de navegacion 3G
Plan de navegacion 4G
Plan de navegacion 3G Empresarial
Plan de navegacion 4G Empresarial
Plan de servicios 3G
Plan de servicios 4G
Plan navegación Datos

I want this result is limited to the following (Only 3G, 4G):

Plan de navegacion 3G
Plan de navegacion 4G
Plan de navegacion 3G Empresarial
Plan de navegacion 4G Empresarial

I am using the following search pattern but I did not properly filtered results:

  • Upper(PLAN_GSM),'(NAVEGA){1}|(3G|4G|5G)'
  • Upper(PLAN_GSM),'((NAVEGA)+)(3G|4G)+'

I have done several tests and do not find the solution. Someone could give me hints?

like image 798
alejomarchan Avatar asked Dec 29 '25 16:12

alejomarchan


2 Answers

You could simply use LIKE, as below:

select *
from mytable
where PLAN_GSM LIKE 'Plan de navegacion _G%';

or use REGEXP_LIKE, as below:

select *
from mytable
where REGEXP_LIKE(PLAN_GSM, '^Plan de navegacion (3|4|5)G(*)');

SQL Fiddle demo

Reference:

Oracle/PLSQL: REGEXP_LIKE Condition on Tech on the Net

like image 135
Joseph B Avatar answered Jan 01 '26 05:01

Joseph B


You can use this:

SELECT * FROM mytable 
WHERE REGEXP_LIKE(mycolumn, '\APlan de navegacion \dG.*\z', 'c');
  • \d represents a digit
  • \A is the beginning of the string
  • .* greedily matches any characters
  • \z is the end of the string
like image 26
zx81 Avatar answered Jan 01 '26 07:01

zx81



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!