2016-11-27 47 views
1

在PL/SQL函數的多個屬性,我試圖寫一個函數與下面的代碼:檢索在SELECT

CREATE OR REPLACE FUNCTION Lib_func(id number,dateToday date) 
RETURN number IS retVal number(1); 

myBorrower number; 
myBook number; 

BEGIN 

SELECT P.book_id INTO myBook, P.request_id INTO myBorrower 
    FROM My_requests P 
    WHERE P.book_id = book_id AND ROWNUM <=1; 

//some if condition which updates value of retVal 
RETURN retVal; 
END; 
/

問題是,這會導致錯誤,當我編譯。如果我刪除第二件事(即P.request_id INTO myBorrower),那麼錯誤將被刪除。 我不能在單個查詢中選擇兩件事嗎?

回答

1

選擇多個變量的語法是:

SELECT P.book_id , P.request_id 
INTO myBook,myBorrower 
FROM My_requests P 
WHERE P.book_id = book_id AND ROWNUM <=1; 
+0

哦okayy。非常感謝! – Manahil