函数plsql add添加员工的工资

inn6fuwd  于 2021-07-26  发布在  Java
关注(0)|答案(2)|浏览(341)

我需要帮助!!我想使用一个函数来添加某个特定部门的员工的工资,但得到的错误是:“exact fetch中指定的数字小于返回的行数。”

CREATE OR REPLACE FUNCTION SUMAR_SALARIOS (i NUMBER) RETURN NUMBER IS resultado NUMBER; BEGIN resultado := resultado + i; RETURN(resultado);
END SUMAR_SALARIOS; / SET SERVEROUTPUT ON SET VERIFY OFF
SET ECHO OFF ACCEPT codigo PROMPT ”Introduce el codigo de departamento” DECLARE
salario_ employees.salary%TYPE;   
codigo_dep number;
BEGIN
codigo_dep := &codigo; 
SELECT salary INTO salario_
FROM employees WHERE department_id = codigo_dep;
DBMS_OUTPUT.PUT_LINE(SUMAR_SALARIOS(salario_));

END;
/
UNDEFINE codigo`
8dtrkrch

8dtrkrch1#

你的问题 SELECT salary INTO salario_ FROM employees WHERE department_id = codigo_dep 返回多行,这就是出现错误的原因。如果要获取某个具体部门中所有员工的工资总额,则应使用以下查询:

SELECT sum(salary) INTO salario_ FROM employees WHERE department_id = codigo_dep
qcbq4gxm

qcbq4gxm2#

你可以这样运行:

set serveroutput on
SET VERIFY OFF
SET ECHO OFF 
ACCEPT codigo_dep NUMBER PROMPT "Introduce el codigo de departamento"

declare
    sumar_salarios number;
begin
    SELECT sum(salary) INTO sumar_salarios
    FROM mwp_alexs_1.employees WHERE department_id = &codigo_dep;

    dbms_output.put_line('sumar_salarios: '||sumar_salarios);
end;
/

相关问题