简体   繁体   English

输出有问题。 错误的确切提取次数少于返回的行数?

[英]Trouble with output. Error exact fetch is less than rows returned?

I am brand new to PL/SQL and I am having trouble with the output of this code. 我是PL / SQL的新手,此代码的输出有麻烦。 I have a populated employee table that contains the employee name, job, pay, id, etc. What I need is for my output to display as following: 我有一个填充的雇员表,其中包含雇员姓名,工作,薪水,身份证等。我需要的是输出显示如下:

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

I keep getting the error exact fetch returns more than rows requested 我不断收到错误,确切的获取返回的行数超过了请求的行数

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;

I think I am close? 我想我很近吗? Any help would be great! 任何帮助将是巨大的!

Your SELECT statement returns more than one row which means the SELECT INTO statement will fail with your "exact fetch returns more than requested number of rows" error. 您的SELECT语句返回多个行,这意味着SELECT INTO语句将失败,并显示“精确获取返回的行数超过请求的行数”错误。

Try adding a WHERE clause that will mean the SELECT statement will only ever return one row. 尝试添加WHERE子句,这将意味着SELECT语句将仅返回一行。 I'm guessing by your code, you want to do something like this: 我猜你的代码,你想做这样的事情:

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;

Check out http://www.techonthenet.com/oracle/errors/ora01422.php for more info regarding the error. 请查看http://www.techonthenet.com/oracle/errors/ora01422.php ,以获取有关该错误的更多信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误是期望的列数少于返回的列数 - Error is Expecting less columns than returned 通知错误ORA-01422:精确获取返回的行数超过了请求的行数 - Informe de error ORA-01422: exact fetch returns more than requested number of rows WHILE循环中的错误:ORA-01422:精确获取返回的行数超过了请求的行数 - Error in WHILE loop: ORA-01422: exact fetch returns more than requested number of rows ORA-01422:精确获取返回的行数超过了请求的行数触发错误 - ORA-01422: exact fetch returns more than requested number of rows Trigger error PL / SQL错误-精确提取返回的行数超过了请求的行数 - PL/SQL Error - exact fetch returns more than requested number of rows 将值插入表时,精确提取返回超过请求的行数错误 - Exact fetch returns more than requested number of rows error while inserting value to the table pl/sql 触发器错误:精确获取返回的行数超过请求的行数 - pl/sql trigger error : exact fetch returns more than requested number of rows SQL错误:ORA-01422:“精确提取返回的行数超过了请求的行数” - SQL Error: ORA-01422: “exact fetch returns more than requested number of rows” ORACLE 错误报告 ORA-01422:精确提取返回的行数超过请求的行数? - ORACLE Error report ORA-01422: exact fetch returns more than requested number of rows? SQL过程错误精确提取返回超过请求的行数 - SQL Procedure error exact fetch returns more than requested number of rows
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM