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

83. Examine the data in the CUST_NAME column of the CUSTOMERS table.

CUST_NAME

Lex De Haan

Renske Ladwig

Jose Manuel Urman

Jason Mallin

You want to extract only those customer names that have three names and display the * symbol in place

of the first name as follows:

CUST NAME

*** De Haan

**** Manuel Urman

Which two queries give the required output? (Choose two.)

A. SELECT LPAD(SUBSTR(cust_name,INSTR(cust_name,' ')),LENGTH(cust_name),'*') "CUST NAME"

FROM customers

WHERE INSTR(cust_name, ' ',1,2)<>0; 

B. SELECT LPAD(SUBSTR(cust_name,INSTR(cust_name,' ')),LENGTH(cust_name),'*') "CUST NAME"

FROM customers

WHERE INSTR(cust_name, ' ',-1,2)<>0; 

C.  SELECT  LPAD(SUBSTR(cust_name,INSTR(cust_name,'  ')),LENGTH(cust_name)-

INSTR(cust_name,' '),'*') "CUST NAME"

FROM customers

WHERE INSTR(cust_name, ' ',-1,-2)<>0;

D.  SELECT  LPAD(SUBSTR(cust_name,INSTR(cust_name,'  ')),LENGTH(cust_name)-

INSTR(cust_name,' '),'*') "CUST NAME"

FROM customers

WHERE INSTR(cust_name, ' ',1,2)<>0 ;

Answer: AB

答案解析:

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

题意要求找出三个名字的,并且将第一个名字使用*替代。


instr( string1, string2, start_position,nth_appearance ) 
string1
源字符串,要在此字符串中查找。
string2
要在string1中查找的字符串 。
start_position
代表string1 的哪个位置开始查找。此参数可选,如果省略默认为1. 字符串索引从1开始。如果此参数为正,从左到右开始检索,如果此参数为负,从右到左检索,返回要查找的字符串在源字符串中的开始索引。
nth_appearance
代表要查找第几次出现的string2. 此参数可选,如果省略,默认为 1.如果为负数系统会报错。


INSTR(cust_name, ' ',1,2)<>0和INSTR(cust_name, ' ',-1,2)<>0确定空格第二次出现的位置能找到,即不等于0.

也即是说有三个名字。

C的where条件不对。

LPAD(SUBSTR(cust_name,INSTR(cust_name,' ')),LENGTH(cust_name),'*')

即是INSTR(cust_name,' ')找出第一个空格的位置。


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

SUBSTR(cust_name,INSTR(cust_name,' '))输出第一个空格之后的字符,即是输出第二个名字和第三个名字


LPAD:返回一个表达式,左边使用一个字符表达式填充到n 个字符的长度

 LPAD(SUBSTR(cust_name,INSTR(cust_name,' ')),LENGTH(cust_name),'*')根据cust_name,来让*替代第一个名字。



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