Http://www.itpub.net/thread-1499223-10-1.html 93楼 我创建了这张表并填入数据: CREATE TABLE plch_new_parts
Http://www.itpub.net/thread-1499223-10-1.html
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.
_匹配单个字符,%匹配任意个字符,*和?是忽悠人的。
--结束END--
本文标题: 2011-10-28 LIKE条件中的通配符
本文链接: https://www.lsjlt.com/news/48239.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-15
2024-05-15
2024-05-15
2024-05-15
2024-05-15
2024-05-15
2024-05-15
2024-05-15
2024-05-14
2024-05-14
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0