我正在尝试执行以下程序,但继续得到以下内容:
CODE:
SET SERVEROUTPUT ON
DECLARE
aID VARCHAR2(4):= '&AuthID';
aName BK_AUTHOR.FNAME%TYPE;
aSurname BK_AUTHOR.LNAME%TYPE;
bTit BK_BOOKS.TITLE%TYPE;
bCat BK_BOOKS.CATEGORY%TYPE;
bPrice BK_COSTS.COST%TYPE;
BEGIN
book_info(aID,aName,aSurname,bTit,bCat,bPrice);
DBMS_OUTPUT.PUT_LINE(aName||'-'||aSurname||'wrote the book ('||bTit||') that is in category '||bCat||' and it cost R'||TO_CHAR(bPrice,'99999.99'));
END;
/
错误
ERROR at line 1:
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at "SYS.BOOK_INFO", line 13
ORA-06512: at line 9
从评论中添加代码:
CREATE OR REPLACE PROCEDURE book_info(
AuthID IN OUT VARCHAR2,
Name OUT BK_AUTHOR.FNAME%TYPE,
Surname OUT BK_AUTHOR.LNAME%TYPE,
Tit OUT BK_BOOKS.TITLE%TYPE,
Cat OUT BK_BOOKS.CATEGORY%TYPE,
Price OUT BK_COSTS.COST%TYPE )
IS
BEGIN
SELECT FNAME,
LNAME,
TITLE,
CATEGORY,
COST
INTO Name,
Surname,
Tit,
Cat,
Price
FROM BK_BOOKS,
BK_AUTHOR,
BK_COSTS
WHERE BK_COSTS.ISBN = BK_BOOKS.ISBN
AND BK_BOOKS.AUTHORID = AuthID;
END book_info;
/
答案 0 :(得分:0)
可能是由于查看book_info代码的多种原因。
首先 - bk_books和bk_author之间存在交叉连接。您需要在这两个表之间添加连接条件,例如 -
WHERE BK_COSTS.ISBN = BK_BOOKS.ISBN AND bk_books.authorid = bk_author.authorid AND AND BK_BOOKS.AUTHORID = AuthID
您还应该根据Authorid检查这些表的结果连接中的重复项。
修改:忘记提及,请不要将SYS用户用于任何与开发相关的活动,例如创建程序或功能。从错误消息中,似乎book_info过程在SYS用户中。除非您是DBA并将其用于与sysdba相关的活动,否则不应该登录此用户。