The EMPLOYEES table contains these columns:
EMPLOYEE_ID NUMBER(4)
LAST_NAME VARCHAR2 (25)
JOB_ID VARCHAR2(10)
You want to search for strings that contain 'SA_' in the JOB_ID column. Which SQL statement do you
use?
A. SELECT employee_id, last_name, job_id
FROM employees
WHERE job_id LIKE '%SA\_%' ESCAPE '\';
B. SELECT employee_id, last_name, job_id
FROM employees
WHERE job_id LIKE '%SA_%';
C. SELECT employee_id, last_name, job_id
FROM employees
WHERE job_id LIKE '%SA_' ESCAPE "\";
D. SELECT employee_id, last_name, job_id
FROM employees
WHERE job_id = '%SA_';
Answer: A
为什么答案是A呢?B不行吗?
------解决方案--------------------------------------------------------
B不行。在LIKE中,_表示匹配任意单个字符,%表示匹配任意单个或多个字符
所以B中LIKE '%SA_%'表示就是含SA字符的JOB_ID,而不是sa_了。
------解决方案--------------------------------------------------------
'_'在oracle中是通配符,现在又要求查找的字符串中含'_',所以加个ESCAPE \,表示不将ESCAPE \后的字符做oracle关键字处理。
网上资料很详细的。
------解决方案--------------------------------------------------------
哈哈,没事干。看着分不少,来接点分。
------解决方案--------------------------------------------------------
A正确!
验证一下不就知道了吗?
SQL> select * from emp where job like '%E_%';
EMPNO ENAME JOB MGR HIREDATE SAL COMM
---------- ---------- -------------------- ---------- ---------- ---------- ---------- -
7369 SMITH CLERK 7902 17-12月-80 800
7499 ALLEN SALESMAN 7698 20-2月 -81 1600 300
7521 WARD SALESMAN 7698 22-2月 -81 1250 500
7566 JONES MANAGER 7839 02-4月 -81 2975
7654 MARTIN SALESMAN 7698 28-9月 -81 1250 1400
7698 BLAKE MANAGER 7839 01-5月 -81 2850
7782 CLARK MANAGE_R 7839 09-6月 -81 2450
7839 KING PRE_SIDE_NT 17-11月-81 5000
7844 TURNER SALESMAN 7698 08-9月 -81 1500 0
7876 ADAMS CLERK 7788 23-5月 -87 1100
7900 JAMES CLERK 7698 03-12月-81 950
EMPNO ENAME JOB MGR HIREDATE SAL COMM
---------- ---------- -------------------- ---------- ---------- ---------- ---------- -
7934 MILLER CLE_RK 7782 23-1月 -82 1300
已选择12行。
SQL> select * from emp where job like '%E\_%'escape'\';
EMPNO ENAME JOB MGR HIREDATE SAL COMM
---------- ---------- -------------------- ---------- ---------- ---------- ---------- -
7782 CLARK MANAGE_R 7839 09-6月 -81 2450
7839 KING PRE_SIDE_NT 17-11月-81 5000
7934 MILLER CLE_RK 7782 23-1月 -82 1300
SQL>
------解决方案--------------------------------------------------------
如果楼主没有问,看来我也是选B的了;