我試圖從cards
的表中隨機選擇一個卡,其中列c_value
和c_suit
使用過程。選擇它後,程序應將該條目的taken
字段更新爲'Y'。ORA-02014-如何從表中隨機選擇一行進行更新?
create or replace procedure j_prc_sel_card(p_value OUT number,
p_suit OUT number)
AS
CURSOR CUR_GET_RAND_CARD IS SELECT c_value,
c_suit
FROM (SELECT c_value,
c_suit,
taken
FROM jackson_card
ORDER BY dbms_random.value)
WHERE rownum = 1
FOR UPDATE OF taken;
BEGIN
OPEN CUR_GET_RAND_CARD;
FETCH CUR_GET_RAND_CARD into p_value, p_suit;
UPDATE jackson_card
SET taken = 'Y'
WHERE c_value = p_value
AND c_suit = p_suit;
CLOSE CUR_GET_RAND_CARD;
END;
然後,我試圖獲取選定的卡並輸出它作爲開始。有了這個:
SET serveroutput on;
DECLARE v_value number;
v_suit number;
BEGIN
j_prc_sel_card(p_value => v_value,p_suit => v_suit);
DBMS_OUTPUT.PUT_LINE(v_value);
DBMS_OUTPUT.PUT_LINE(v_suit);
END;
/
但是我得到了標題中所述的錯誤,看來我選擇一個隨機卡的方式,從做一個更新停止我。提前致謝!