PL/SQL 上机练习(一)

_(:_」∠)_ _(:_」∠)_ _(:_」∠)_骗访问量系列_(:_」∠)_ _(:_」∠)_ _(:_」∠)_

题目描述:

对员工表中所有员工的姓名做如下处理:姓名的首字母在'A'到'G' 之间,合并为第一个字符串,在'H'到'O'之间,合并为第二个字符串,在'P'到'Z'之间,合并为第三个字符串,姓名之间用空格相隔。

代码:

DECLARE
str1 string(100);
str2 string(100);
str3 string(100);
CURSOR NAME_AG IS
SELECT ENAME FROM EMP WHERE substr(ENAME,0,1) BETWEEN 'A' AND 'G';
name1 emp.ENAME%TYPE;
CURSOR NAME_HO IS
SELECT ENAME FROM EMP WHERE substr(ENAME,0,1) BETWEEN 'H' AND 'O';
name2 emp.ENAME%TYPE;
CURSOR NAME_PZ IS
SELECT ENAME FROM EMP WHERE substr(ENAME,0,1) BETWEEN 'P' AND 'Z';
name3 emp.ENAME%TYPE;
BEGIN
OPEN NAME_AG;
OPEN NAME_HO;
OPEN NAME_PZ;

LOOP
    FETCH NAME_AG INTO name1;
    EXIT WHEN NAME_AG%NOTFOUND;
    str1:=str1||name1||' ';
END LOOP;
LOOP
    FETCH NAME_HO INTO name2;
    EXIT WHEN NAME_HO%NOTFOUND;
    str2:=str2||name2||' ';
END LOOP;
LOOP
    FETCH NAME_PZ INTO name3;
    EXIT WHEN NAME_PZ%NOTFOUND;
    str3:=str3||name3||' ';
END LOOP;
dbms_output.put_line(str1);
dbms_output.put_line(str2);
dbms_output.put_line(str3);
END;

 |版权声明:本文为博主原创文章,未经博主允许不得转载。

posted @ 2018-04-03 20:34  zhaoGavin  阅读(313)  评论(0编辑  收藏  举报