0

我是 PL/SQL 的新手,我在输出这段代码时遇到了问题。我有一个填充的员工表,其中包含员工姓名、工作、工资、身份证等。我需要的是我的输出显示如下:

Employee Name:       Johnson
Job:                 Service Writer
Total Pay:           $32,000

我不断收到错误,确切的提取返回比请求的行多

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;

我想我很接近?任何帮助都会很棒!

4

1 回答 1

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以获取有关该错误的更多信息。

于 2013-04-17T19:16:04.900 回答