2011-10-28LIKE条件中的通配符-创新互联
/tupian/20230522/thread-1499223-10-1.html
成都创新互联,为您提供网站建设公司、成都网站制作、网站营销推广、网站开发设计,对服务成都纯水机等多个行业拥有丰富的网站建设及推广经验。成都创新互联网站建设公司成立于2013年,提供专业网站制作报价服务,我们深知市场的竞争激烈,认真对待每位客户,为客户提供赏心悦目的作品。 与客户共同发展进步,是我们永远的责任!93楼
我创建了这张表并填入数据:
CREATE TABLE plch_new_parts ( partnum NUMBER , partname VARCHAR2 (50) ) / BEGIN INSERT INTO plch_new_parts (partnum, partname) VALUES (1, 'MY PART NUMBER 1'); INSERT INTO plch_new_parts (partnum, partname) VALUES (2, 'MY_PART_NUMBER_2'); INSERT INTO plch_new_parts (partnum, partname) VALUES (3, 'MY_PART NUMBER_3'); COMMIT; END; /
当我执行下列这段代码,屏幕上会显示什么?
DECLARE l_counts DBMS_SQL.number_table; BEGIN l_counts (1) := 0; l_counts (2) := 0; l_counts (3) := 0; l_counts (4) := 0; FOR rec IN ( SELECT partname FROM plch_new_parts ORDER BY partnum) LOOP IF rec.partname LIKE 'MY PART NUMBER %' THEN l_counts (1) := l_counts (1) + 1; END IF; IF rec.partname LIKE 'MY_PART_NUMBER_%' THEN l_counts (2) := l_counts (2) + 1; END IF; IF rec.partname LIKE 'MY_PART NUMBER_%' THEN l_counts (3) := l_counts (3) + 1; END IF; IF rec.partname LIKE 'MY?PART?NUMBER?*' THEN l_counts (4) := l_counts (4) + 1; END IF; END LOOP; FOR indx IN 1 .. l_counts.COUNT LOOP DBMS_OUTPUT.put_line (l_counts (indx)); END LOOP; END; /
(A)
1 1 1 0
(B)
1 3 2 0
(C)
0 0 0 3
(D)
3 3 3 3
(E)
1 3 2 3
运行结果如下
SQL> DECLARE 2 l_counts DBMS_SQL.number_table; 3 4 BEGIN 5 l_counts (1) := 0; 6 l_counts (2) := 0; 7 l_counts (3) := 0; 8 l_counts (4) := 0; 9 10 FOR rec IN ( SELECT partname 11 FROM plch_new_parts 12 ORDER BY partnum) 13 LOOP 14 IF rec.partname LIKE 'MY PART NUMBER %' 15 THEN 16 l_counts (1) := l_counts (1) + 1; 17 END IF; 18 19 IF rec.partname LIKE 'MY_PART_NUMBER_%' 20 THEN 21 l_counts (2) := l_counts (2) + 1; 22 END IF; 23 24 IF rec.partname LIKE 'MY_PART NUMBER_%' 25 THEN 26 l_counts (3) := l_counts (3) + 1; 27 END IF; 28 29 IF rec.partname LIKE 'MY?PART?NUMBER?*' 30 THEN 31 l_counts (4) := l_counts (4) + 1; 32 END IF; 33 END LOOP; 34 35 FOR indx IN 1 .. l_counts.COUNT 36 LOOP 37 DBMS_OUTPUT.put_line (l_counts (indx)); 38 END LOOP; 39 END; 40 / 1 3 2 PL/SQL procedure successfully completed SQL>
答案B
答案说明96楼
2011-10-28答案B. _匹配单个字符,%匹配任意个字符,*和?是忽悠人的。
当前题目:2011-10-28LIKE条件中的通配符-创新互联
转载注明:http://ybzwz.com/article/dgesei.html