Plsql 用编译错误创建的过程,不知道发生了什么

Plsql 用编译错误创建的过程,不知道发生了什么,plsql,Plsql,我刚在大学开始学习这门课程,无论我做什么都不能让它起作用 供参考 表dept包含deptno和dname,deptno是department的id,dname是名称 emp包含empno,whcih是员工姓名,deptno是相同的部门id,并且已连接。Emils,您的代码中有一些严重的语法错误。PL/SQL语法和语义的快速参考指南可在中查看。 您的代码可以这样更改: create or replace procedure d_name_legzdins (id in dept.deptno%ty

我刚在大学开始学习这门课程,无论我做什么都不能让它起作用

供参考

表dept包含deptno和dname,deptno是department的id,dname是名称


emp包含empno,whcih是员工姓名,deptno是相同的部门id,并且已连接。Emils,您的代码中有一些严重的语法错误。PL/SQL语法和语义的快速参考指南可在中查看。 您的代码可以这样更改:

create or replace procedure d_name_legzdins (id in dept.deptno%type) as d_name_legzdins varchar(20);

BEGIN

SELECT dname into d_count_legzdins FROM dept WHERE deptno=id;

if (SELECT count(empno) from emp where deptno=id)=0 THEN

raise_application_error(-20101, 'There are no employees currently working at this department!');

else

DBMS_OUTPUT.PUT_LINE('There are currently '|| (SELECT count(empno) from emp where deptno=id) ||' employees working at '|| d_count_legzdins ||'department');

END IF;

exception

  when no_data_found then

    DBMS_OUTPUT.PUT_LINE('There is no such department!');

end;'

正如前面指出的,您有一些严重的语法错误。清洁这些显然是你的首要任务。然而,我认为你的程序的布局有点起伏。你有一个结构,好的过程,错误的过程,好的过程,错误的过程。我发现一个更干净的过程是一个好的过程,而所有的异常处理有时候是不可能的。在这种情况下,缺少部门和部门中没有Emp都是例外。因此,请在例外部分处理这两个问题。Oracle允许嵌套块,并且每个块都可以有一个异常部分:因此类似于see fiddle]的内容


我不明白为什么您只希望收到一条关于缺少礼仪的消息,但用户定义的例外情况不适用于任何员工,但不一致性是您的选择。

我已经确定,这是子查询的问题,您很可能会收到一个完整的错误,因为有许多语法错误。当发生这种情况时,您可以通过显示sqlPlus或IDE中的错误,或者通过从用户错误中选择*来查找这些错误(如果不可用)。这将告诉您编译器不喜欢什么。如果您需要询问,请在您的问题中发布这些信息。此外,您还应该花一些时间来学习和复习.OOPS。忘了标题。
create or replace procedure d_name_legzdins (id in dept.deptno%type) 
as 
  v_name_legzdins varchar(20);
  v_emp_cnt number;
begin
 select dname 
 into v_name_legzdins 
 from dept 
 where deptno=id;
 
 begin
   select count(empno)
   into v_emp_cnt
   from  emp where 
   deptno=id;
 exception
   when no_data_found then
     raise_application_error(-20101, 'There are no employees currently working at this department!');
 end;
 
 DBMS_OUTPUT.PUT_LINE('There are currently '|| v_emp_cnt ||' employees working at '|| v_name_legzdins ||' department'); 

exception
  when no_data_found then
    DBMS_OUTPUT.PUT_LINE('There is no such department!');
end;
create or replace procedure d_name_legzdins (id in dept.deptno%type) 
as 
  v_name_legzdins varchar(20);
  v_emp_cnt number;
  
begin

   select d.dname, count(*) 
     into v_name_legzdins,v_emp_cnt 
     from dept d 
     join emp  e on (e.deptno = d.deptno)
    where d.deptno = id
    group by d.dname; 
 
   dbms_output.put_line('There are currently '|| v_emp_cnt || 
                        ' employees working at '|| v_name_legzdins ||' department'
                        ); 
                        
exception
  when no_data_found then 
    -- at this point we know that either the parameter for department (id) is invalid 
    -- or that it is valid but has no employees. Now discover which.
       begin 
           select dname
             into v_name_legzdins    
            from dept 
            where deptno =  id
              and rownum <= 1; 
           -- the department exists, so it does not have any employees.
           raise_application_error(-20101, 'There are no employees currently working at this department!');

    exception
      when no_data_found then
           dbms_output.put_line('There is no such department!');
    end ; -- inner exception    
end d_name_legzdins;