Examinethe data in the CUST_NAME column of the CUSTOMERS table.
CUST_NAME Lex De Haan Renske Ladwig Jose Manuel Urman Jason Mallin |
You wantto extract only those customer names that have three names and display the *symbol in place of the first name as follows:你想提取那些客户名字有3个名字,显示*
CUST NAME *** De Haan **** Manuel Urman |
Whichtwo 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 ; |
在Oracle/PLSQL中,instr函数返回要截取的字符串在源字符串中的位置。
语法如下:instr( string1, string2, start_position,nth_appearance ) [1] [2]
string1
源字符串,要在此字符串中查找。
string2
要在string1中查找的字符串 。
start_position
代表string1 的哪个位置开始查找。此参数可选,如果省略默认为1. 字符串索引从1开始。如果此参数为正,从左到右开始检索,如果此参数为负,从右到左检索,返回要查找的字符串在源字符串中的开始索引。
nth_appearance
代表要查找第几次出现的string2. 此参数可选,如果省略,默认为 1.如果为负数系统会报错。
注意:
位置索引号从1开始。
如果String2在String1中没有找到,instr函数返回0。
示例:
SELECT instr('syranmo','s') FROM dual; -- 返回 1
SELECT instr('syranmo','ra') FROM dual; -- 返回 3
SELECT instr('syran mo','a',1,2) FROM dual; -- 返回 0