简体   繁体   中英

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?

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

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
select * 
from all_tab_columns 
where COLUMN_NAME like '%MAIN%ACCOUNT%LINK%CODE%N%' and TABLE_NAME like 'CB%' and not regexp_like(table_name,'[0-9]')

The above query will fetch the only object without number of content.

select *
from all_tab_columns 
where COLUMN_NAME like '%MAIN%ACCOUNT%LINK%CODE%N%' and TABLE_NAME like 'CB%' and not regexp_like(table_name,'[0-9]')

The above query will fetch only object with numbers content.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM