需要修改代码以使用部门名称从员工中查找名字,姓氏

时间:2016-02-01 01:56:10

标签: plsql oracle11g

以下代码用于通过部门名称查找员工的名字,姓氏。我收到错误:错误(13,8):PLS-00103但我不知道如何解决它。有什么建议?提前致谢

create or replace procedure xx(a in varchar2)
as
cursor b is select department_name, first_name, last_name from employees;
c employees%rowtype;
begin
open b;
loop
    fetch b into c;
    exit when b%notfound;
        if a = c.department_name then
        dbms_output.put_line(c.first_name);
        dbms_output.put_line(c.last_name);
        elseif DBMS_OUTPUT.PUT_LINE(c.last_name);
        end if;
end loop;
close b;
end;

2 个答案:

答案 0 :(得分:1)

错误(13,8)位于下面一行

elseif DBMS_OUTPUT.PUT_LINE(c.last_name);

您正在使用elsif,但没有任何条件可以测试。 如果你没有比较/测试更多的条件,你也可以使用else而不是elsif

create or replace procedure xx(a in varchar2)
as
cursor b is select department_name, first_name, last_name from employees;
c employees%rowtype;
begin
open b;
loop
    fetch b into c;
    exit when b%notfound;
        if a = c.department_name then
            dbms_output.put_line(c.first_name);
            dbms_output.put_line(c.last_name);
        else 
            DBMS_OUTPUT.PUT_LINE(c.last_name);
        end if;
end loop;
close b;
end;

注意:语法错误会显示您可能出错的行和列

答案 1 :(得分:0)

请尝试以下方法:

create or replace procedure xx(a in varchar2)
as
cursor b is select department_name, first_name, last_name from employees;
c b%rowtype;
begin
open b;
loop
    fetch b into c;
    exit when b%notfound;
        if a = c.department_name then
        dbms_output.put_line(c.first_name);
        dbms_output.put_line(c.last_name);
        elseif DBMS_OUTPUT.PUT_LINE(c.last_name);
        end if;
end loop;
close b;
end;