我是PL / SQL的新手,我遇到了这段代码的输出问题。我有一个填充的员工表,其中包含员工姓名,工作,薪水,身份等。我需要的是输出显示如下:
Employee Name: Johnson
Job: Service Writer
Total Pay: $32,000
我不断收到错误,fetch返回的次数多于请求的行数
ACCEPT p_1 PROMPT 'Please enter the Employee ID:'
DECLARE
v_eid employee.employee_id%TYPE := &p_1;
v_name employee.employee_name%TYPE;
v_job employee.job%TYPE;
v_pay employee.salary%TYPE;
BEGIN
SELECT employee_name, job, salary
INTO v_name, v_job, v_pay
FROM employee;
DBMS_OUTPUT.PUT_LINE('Employee Name: ' || v_name);
DBMS_OUTPUT.PUT_LINE('Job: ' || v_job);
DBMS_OUTPUT.PUT_LINE('Total Pay: ' || v_pay);
END;
我想我很亲近?任何帮助都会很棒!
答案 0 :(得分:1)
您的SELECT
语句返回多行,这意味着SELECT INTO
语句将失败,并且“确切提取的返回次数超过请求的行数”错误。
尝试添加一个WHERE子句,这意味着SELECT语句只返回一行。我猜你的代码,你想做这样的事情:
ACCEPT p_1 PROMPT 'Please enter the Employee ID:'
DECLARE
v_eid employee.employee_id%TYPE := &p_1;
v_name employee.employee_name%TYPE;
v_job employee.job%TYPE;
v_pay employee.salary%TYPE;
BEGIN
SELECT employee_name, job, salary
INTO v_name, v_job, v_pay
FROM employee
WHERE employee_id = v_eid;
DBMS_OUTPUT.PUT_LINE('Employee Name: ' || v_name);
DBMS_OUTPUT.PUT_LINE('Job: ' || v_job);
DBMS_OUTPUT.PUT_LINE('Total Pay: ' || v_pay);
END;
查看http://www.techonthenet.com/oracle/errors/ora01422.php以获取有关错误的更多信息。