一、原题
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 SUBSTR(cust_first_name, -2, 1)='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';
答案:A
二、题目翻译Which query would give the required output?
A. SELECT cust_first_name
FROM customers
WHERE INSTR(cust_first_name, 'e')<>0
AND SUBSTR(cust_first_name, -2, 1)='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';
答案:A
要从CUSTOMERS表中显示所有customers的first names,名字中要包含e,并且倒数第二个字符要包含a
下面哪个查询语句能给出所需的结果?
三、题目解析下面哪个查询语句能给出所需的结果?
A选项正确,INSTR如果不包含字符则返回0,不等于0,说明包含了e字符,SUBSTR可以从倒数第二个字符开始截取一个字符。
B选项不正确,INSTR的结果<>'',永远为false。
C选项不正确,INSTR的结果不可能为null。
D选项不正确,SUBSTR不是截取的倒数第二个字符。
B选项不正确,INSTR的结果<>'',永远为false。
C选项不正确,INSTR的结果不可能为null。
D选项不正确,SUBSTR不是截取的倒数第二个字符。