功能:找出字符串B在字符串A中存在的字符
/********************************************
找出字符串l_b中字母在字符串l_a中存在的字母
**********************************************/
DECLARE
l_a Varchar2(50) := 'ABCDEFGHIK';
l_b VARCHAR2(50) := 'EDGLKJOS';
l_length NUMBER;
l_length2 NUMBER;
TYPE var_a IS TABLE OF VARCHAR2(1) INDEX BY BINARY_INTEGER;
vara var_a;
varb var_a;
v VARCHAR2(1);
l_count NUMBER;
BEGIN
l_length := LENGTH(l_a);
l_length2 := LENGTH(l_b);
l_count := 0;
--把字符串l_a放入数组vara数组中
FOR i IN 1..l_length LOOP
vara(i) := SUBSTRB(l_a,1,1);
l_a := SUBSTRB(l_a,2,l_length);
END LOOP;
--把字符串l_b放入数组varb数组中
FOR i IN 1..l_length2 LOOP
varb(i) := SUBSTRB(l_b,1,1);
l_b := SUBSTRB(l_b,2,l_length2);
END LOOP;
--双重循环找出l_b在l_a中存在的字母
FOR i IN 1..l_length2 LOOP
FOR j IN 1..l_length LOOP
l_COUNT := l_COUNT + 1;
IF varb(i) = vara(j) THEN
dbms_output.put(varb(i) || ' ');
END IF;
END LOOP;
END LOOP;
dbms_output.put_line(l_count);
l_count := 0;
--对l_a进行排序
FOR i IN 1..l_length LOOP
FOR j IN i..l_length LOOP
IF vara(i) > vara(j) THEN
v := vara(i);
vara(i) := vara(j);
vara(j) := v;
END IF;
END LOOP;
END LOOP;
--输出l_a字符串
FOR i IN 1..l_length LOOP
dbms_output.put(vara(i) || ' ');
END LOOP;
dbms_output.put_line('');
--对l_b进行排序
FOR i IN 1..l_length2 LOOP
FOR j IN i..l_length2 LOOP
IF varb(i) > varb(j) THEN
v := varb(i);
varb(i) := varb(j);
varb(j) := v;
END IF;
END LOOP;
END LOOP;
--输出l_b字符串
FOR i IN 1..l_length2 LOOP
dbms_output.put(varb(i) || ' ');
END LOOP;
dbms_output.put_line('');
--先对l_a和l_b进行排序,然后进行比较
FOR i IN 1..l_length LOOP
<>
FOR j IN 1..l_length2 LOOP
l_count := l_count + 1;
IF vara(i) = varb(j) THEN
dbms_output.put(vara(i) || ' ');
EXIT lable_1;
END IF;
END LOOP lable_1;
END LOOP;
dbms_output.put_line(l_count);
END;
/********************************************
找出字符串l_b中字母在字符串l_a中存在的字母
**********************************************/
DECLARE
l_a Varchar2(50) := 'ABCDEFGHIK';
l_b VARCHAR2(50) := 'EDGLKJOS';
l_length NUMBER;
l_length2 NUMBER;
TYPE var_a IS TABLE OF VARCHAR2(1) INDEX BY BINARY_INTEGER;
vara var_a;
varb var_a;
v VARCHAR2(1);
l_count NUMBER;
BEGIN
l_length := LENGTH(l_a);
l_length2 := LENGTH(l_b);
l_count := 0;
--把字符串l_a放入数组vara数组中
FOR i IN 1..l_length LOOP
vara(i) := SUBSTRB(l_a,1,1);
l_a := SUBSTRB(l_a,2,l_length);
END LOOP;
--把字符串l_b放入数组varb数组中
FOR i IN 1..l_length2 LOOP
varb(i) := SUBSTRB(l_b,1,1);
l_b := SUBSTRB(l_b,2,l_length2);
END LOOP;
--双重循环找出l_b在l_a中存在的字母
FOR i IN 1..l_length2 LOOP
FOR j IN 1..l_length LOOP
l_COUNT := l_COUNT + 1;
IF varb(i) = vara(j) THEN
dbms_output.put(varb(i) || ' ');
END IF;
END LOOP;
END LOOP;
dbms_output.put_line(l_count);
l_count := 0;
--对l_a进行排序
FOR i IN 1..l_length LOOP
FOR j IN i..l_length LOOP
IF vara(i) > vara(j) THEN
v := vara(i);
vara(i) := vara(j);
vara(j) := v;
END IF;
END LOOP;
END LOOP;
--输出l_a字符串
FOR i IN 1..l_length LOOP
dbms_output.put(vara(i) || ' ');
END LOOP;
dbms_output.put_line('');
--对l_b进行排序
FOR i IN 1..l_length2 LOOP
FOR j IN i..l_length2 LOOP
IF varb(i) > varb(j) THEN
v := varb(i);
varb(i) := varb(j);
varb(j) := v;
END IF;
END LOOP;
END LOOP;
--输出l_b字符串
FOR i IN 1..l_length2 LOOP
dbms_output.put(varb(i) || ' ');
END LOOP;
dbms_output.put_line('');
--先对l_a和l_b进行排序,然后进行比较
FOR i IN 1..l_length LOOP
<>
FOR j IN 1..l_length2 LOOP
l_count := l_count + 1;
IF vara(i) = varb(j) THEN
dbms_output.put(vara(i) || ' ');
EXIT lable_1;
END IF;
END LOOP lable_1;
END LOOP;
dbms_output.put_line(l_count);
END;
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/28268054/viewspace-1075639/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/28268054/viewspace-1075639/