我有一张桌子,名字:员工。表结构如下:
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');
答案 0 :(得分: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...);
答案 1 :(得分:1)
非正则表达式方法,只是因为regexp可能有点cpu昂贵,或者对于使用pre-regexp Oracle版本的人来说。
select
...
from
...
where
translate(upper(last_name),'EIOU','AAAA') like '%AA%'
select
...
from
...
where
translate(upper(last_name),'EIOU','AAAA') like '%A%A%'