【问题标题】:I need some help about plsql functions我需要一些关于 plsql 函数的帮助
【发布时间】:2019-10-01 11:46:26
【问题描述】:

我想选择employee_id小于200的工资总和。这是我的代码。

declare 
  emp_id number;
  x number;
  function sum_max_salary (emp_id in number)    
    return number 
  is 
    v_result number;
  begin 
    select sum(salary) into v_result from employees 
     where employee_id<200;
    return v_result;
  end;
begin
  emp_id:=200;
  x:=sum_max_salary(emp_id);
  dbms_output.put_line(sum_max_salary);
end;

上面的过程给了我一个错误:

ORA-06550:第 16 行,第 22 列:PLS-00306:调用“SUM_MAX_SALARY”时参数的数量或类型错误

ORA-06550:第 16 行,第 1 列:PL/SQL:语句被忽略 06550。00000 - “第 %s 行,第 %s 列:\n%s” *原因:通常是 PL/SQL 编译错误。 *行动:–

我需要帮助才能找到问题。

【问题讨论】:

  • 您似乎忘记提出任何问题 - 请编辑您的问题以提出问题。你有错误吗?它没有按照您想要的方式工作吗?还有什么?
  • 您的输出试图输出函数调用 (sum_max_summary),而不是结果 (x)。您也不要在函数本身的任何地方使用emp_id

标签: sql oracle plsql


【解决方案1】:

如果您只想执行 SQL:

select sum(salary) 
from employees 
where employee_id<200;

如果你想用 PL/SQL 来做

set servoutput on
declare 
emp_id number;
x number;
function sum_max_salary (emp_id in number)


return number 
is 
v_result number;
begin 
select sum(salary) into v_result from employees 
where employee_id<emp_id;
return v_result;
end;
begin
emp_id:=200;
x:=sum_max_salary(emp_id);
dbms_output.put_line(x);
end;

【讨论】:

    【解决方案2】:

    问题在线

    dbms_output.put_line(sum_max_salary);
    

    你可能想做

    dbms_output.put_line(x);
    

    x 是你函数的结果

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-21
      • 2020-08-13
      • 2014-07-18
      • 2011-08-25
      相关资源
      最近更新 更多