OCP-1Z0-051 第3题 转义字符
2014-04-14 13:59
295 查看
一、原题
You need to extract details of those products in the SALES table where the PROD_ID column contains the string '_D123'.
Which WHERE clause could be used in the SELECT statement to get the required output?
A. WHERE prod_id LIKE '%_D123%' ESCAPE '_'
B. WHERE prod_id LIKE '%\_D123%' ESCAPE '\'
C. WHERE prod_id LIKE '%_D123%' ESCAPE '%_'
D. WHERE prod_id LIKE '%\_D123%' ESCAPE '\_'
答案 B
二、题目翻译
要从SALES表中提取出PROD_ID列包含'_D123'字符串的产品明细。
下面哪一个WHERE条件子句可以获得所需的输出结果?
三、题目解析
ESCAPE子句为指定转译字符,因为'_'下画线在LIKE子句中指的是任意一个字符,所以需要把'_'下画线进行转义,转义字符设置为'\'。
四、实验
SQL> drop table test;
Table dropped.
SQL> create table test(id int,prod_id varchar2(20));
Table created.
SQL> insert into test values(1,'123_D123abc');
1 row created.
SQL> insert into test values(2,'123abc');
1 row created.
SQL> insert into test values(3,'D123');
1 row created.
SQL> insert into test values(4,'Da123');
1 row created.
SQL> commit;
Commit complete.
SQL> select * from test;
ID PROD_ID
---------- ----------------------------------------
1 123_D123abc
2 123abc
3 D123
4 Da123
SQL> select * from test
2 WHERE prod_id LIKE '%_D123%' ESCAPE '_';
WHERE prod_id LIKE '%_D123%' ESCAPE '_'
*
ERROR at line 2:
ORA-01424: missing or illegal character following the escape character
SQL> select * from test
2 WHERE prod_id LIKE '%\_D123%' ESCAPE '\';
ID PROD_ID
---------- ----------------------------------------
1 123_D123abc
SQL> select * from test
2 WHERE prod_id LIKE '%_D123%' ESCAPE '%_';
WHERE prod_id LIKE '%_D123%' ESCAPE '%_'
*
ERROR at line 2:
ORA-01425: escape character must be character string of length 1
SQL> select * from test
2 WHERE prod_id LIKE '%\_D123%' ESCAPE '\_';
WHERE prod_id LIKE '%\_D123%' ESCAPE '\_'
*
ERROR at line 2:
ORA-01425: escape character must be character string of length 1
You need to extract details of those products in the SALES table where the PROD_ID column contains the string '_D123'.
Which WHERE clause could be used in the SELECT statement to get the required output?
A. WHERE prod_id LIKE '%_D123%' ESCAPE '_'
B. WHERE prod_id LIKE '%\_D123%' ESCAPE '\'
C. WHERE prod_id LIKE '%_D123%' ESCAPE '%_'
D. WHERE prod_id LIKE '%\_D123%' ESCAPE '\_'
答案 B
二、题目翻译
要从SALES表中提取出PROD_ID列包含'_D123'字符串的产品明细。
下面哪一个WHERE条件子句可以获得所需的输出结果?
三、题目解析
ESCAPE子句为指定转译字符,因为'_'下画线在LIKE子句中指的是任意一个字符,所以需要把'_'下画线进行转义,转义字符设置为'\'。
四、实验
SQL> drop table test;
Table dropped.
SQL> create table test(id int,prod_id varchar2(20));
Table created.
SQL> insert into test values(1,'123_D123abc');
1 row created.
SQL> insert into test values(2,'123abc');
1 row created.
SQL> insert into test values(3,'D123');
1 row created.
SQL> insert into test values(4,'Da123');
1 row created.
SQL> commit;
Commit complete.
SQL> select * from test;
ID PROD_ID
---------- ----------------------------------------
1 123_D123abc
2 123abc
3 D123
4 Da123
SQL> select * from test
2 WHERE prod_id LIKE '%_D123%' ESCAPE '_';
WHERE prod_id LIKE '%_D123%' ESCAPE '_'
*
ERROR at line 2:
ORA-01424: missing or illegal character following the escape character
SQL> select * from test
2 WHERE prod_id LIKE '%\_D123%' ESCAPE '\';
ID PROD_ID
---------- ----------------------------------------
1 123_D123abc
SQL> select * from test
2 WHERE prod_id LIKE '%_D123%' ESCAPE '%_';
WHERE prod_id LIKE '%_D123%' ESCAPE '%_'
*
ERROR at line 2:
ORA-01425: escape character must be character string of length 1
SQL> select * from test
2 WHERE prod_id LIKE '%\_D123%' ESCAPE '\_';
WHERE prod_id LIKE '%\_D123%' ESCAPE '\_'
*
ERROR at line 2:
ORA-01425: escape character must be character string of length 1
相关文章推荐
- OCP-1Z0-051 补充题库 第3题 隐式格式转换
- OCP-1Z0-051 第58题 转义字符escape
- OCP-1Z0-051-题目解析-第3题
- OCP-1Z0-051-2015-52题
- OCP-1Z0-051-V9.02-18题
- OCP-1Z0-051-V9.02-32题
- OCP-1Z0-051-V9.02-33题
- OCP-1Z0-051-V9.02-142题
- OCP-1Z0-051-V9.02-110题
- OCP-1Z0-051-V9.02-148题
- OCP-1Z0-051-V9.02-30题
- OCP-1Z0-051-V9.02-67题
- OCP-1Z0-051-V9.02-101题
- OCP-1Z0-051-V9.02-131题
- OCP-1Z0-051-V9.02-172题
- OCP-1Z0-051-V9.02-7题
- OCP-1Z0-051-V9.02-36题
- OCP-1Z0-051-V9.02-13题 单引号的使用
- OCP-1Z0-051-V9.02-128题
- OCP-1Z0-新051-61题版本-14