OCP-1Z0-051-V9.02-76题

76. You need to display the first names of all customers from the CUSTOMERS table that contain the

character 'e' and have the character 'a' in the second last position.

Which query would give the required output?

A. SELECT cust_first_name

FROM customers

WHERE INSTR(cust_first_name, 'e')<>0 AND         e存在    

SUBSTR(cust_first_name, -2, 1)='a'; 倒数第二个是a

B. SELECT cust_first_name

FROM customers

WHERE INSTR(cust_first_name, 'e')<>'' AND            

SUBSTR(cust_first_name, -2, 1)='a';

C. SELECT cust_first_name

FROM customers

WHERE INSTR(cust_first_name, 'e')IS NOT NULL  AND            

SUBSTR(cust_first_name, 1,-2)='a';

D. SELECT cust_first_name

FROM customers

WHERE INSTR(cust_first_name, 'e')<>0 AND            

SUBSTR(cust_first_name, LENGTH(cust_first_name),-2)='a';

Answer: A

 答案解析:

参考:http://blog.csdn.net/rlhua/article/details/12848395

SUBSTR:提取确定长度的字符串

SUBSTR(cust_first_name, -2, 1)='a'意思是cust_first_name从右边开始数,第二个字符是a

INSTR:查找指定字符串的数字位置,如果没有找到,instr函数返回0

 INSTR(cust_first_name, 'e')确定是否有e这个字符,有则输出器位置,没有则输出0,。

则A正确。


INSTR(源字符串, 目标字符串, 起始位置, 匹配序号)

  在oracle/PLSQL中,instr函数返回要截取的字符串在源字符串中的位置。只检索一次,就是说从字符的开始到字符的结尾就结束。

  语法如下:instr( string1, string2 [, start_position [, nth_appearance ] ] )

  参数分析:string1源字符串,要在此字符串中查找。

  string2要在string1中查找的字符串.

  start_position代表string1 的哪个位置开始查找。此参数可选,如果省略默认为1. 字符串索引从1开始。如果此参数为正,从左到右开始检索,如果此参数为负,从右到左检索,返回要查找的字符串在源字符串中的开始索引。

  nth_appearance代表要查找第几次出现的string2. 此参数可选,如果省略,默认为 1.如果为负数系统会报错。

  注意:如果String2在String1中没有找到,instr函数返回0.



原文地址:https://www.cnblogs.com/hzcya1995/p/13316897.html