[英]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.