-1

我有一张桌子,名字:员工。表结构(的)如下:

CREATE TABLE  "EMPLOYEES" 
   (    "EMP_ID" NUMBER(6,0), 
    "FIRST_NAME" VARCHAR2(20), 
    "LAST_NAME" VARCHAR2(25) CONSTRAINT "EMP_LAST_NAME_NN" NOT NULL ENABLE, 
    "EMAIL" VARCHAR2(25) CONSTRAINT "EMP_EMAIL_NN" NOT NULL ENABLE, 
    "HIRE_DATE" DATE CONSTRAINT "EMP_HIRE_DATE_NN" NOT NULL ENABLE, 
    "JOB_ID" VARCHAR2(10) CONSTRAINT "EMP_JOB_NN" NOT NULL ENABLE, 
    "SALARY" NUMBER(8,2), 
    "COMMI_PCT" NUMBER(2,2), 
    "MANAGER_ID" NUMBER(6,0), 
    "DEP_ID" NUMBER(4,0), 
     CONSTRAINT "EMP_SALARY_MIN" CHECK (salary > 0) ENABLE, 
     CONSTRAINT "EMP_EMAIL_UK" UNIQUE ("EMAIL") ENABLE, 
     CONSTRAINT "EMP_EMP_ID_PK" PRIMARY KEY ("EMP_ID") ENABLE, 
     CONSTRAINT "EMP_DEPT_FK" FOREIGN KEY ("DEP_ID")
      REFERENCES  "DEPARTMENTS" ("DEPARTMENT_ID") ENABLE, 
     CONSTRAINT "EMP_JOB_FK" FOREIGN KEY ("JOB_ID")
      REFERENCES  "JOBS" ("JOB_ID") ENABLE, 
     CONSTRAINT "EMP_MANAGER_FK" FOREIGN KEY ("MANAGER_ID")
      REFERENCES  "EMPLOYEES" ("EMP_ID") ENABLE
   )

我想显示那些包含元音对的员工姓名。

我只是尝试一下:

SELECT EMP_ID,JOB_ID,last_name 
FROM employees 
WHERE REGEXP_LIKE (last_name, '([aeiou])\1');
4

2 回答 2

2

如果你的意思是两个元音连续(大写和小写),你可以使用:

select *
from employees
where regexp_like(last_name,'[aeiouAEIOU]{2}');

如果您的意思是在任何地方都可以使用两个元音:

select *
from employees
where regexp_like(last_name,'[aeiouAEIOU].*[aeiouAEIOU]');

如果由于某种原因您不能使用正则表达式,则必须想出两个元音的每个组合并执行以下操作:

select * from employess
where (
     last_name like '%a%a%' 
  or last_name like '%a%e%'
  or last_name like '%a%i%'
  etc...);
于 2013-07-30T16:52:12.867 回答
1

非正则表达式方法,只是因为正则表达式可能有点 cpu-expensive,或者对于使用预正则表达式 Oracle 版本的人来说。

连续元音

select
  ...
from
  ...
where
  translate(upper(last_name),'EIOU','AAAA') like '%AA%'

不连续的元音

select
  ...
from
  ...
where
  translate(upper(last_name),'EIOU','AAAA') like '%A%A%'
于 2013-12-06T11:19:17.290 回答