oracle - ORA-02014- How do I update a randomly selected row from a table? -


I tried to randomly select card a card from a table with the columns be'm a using the procedure c_value and c_suit after selecting it, the process has been field 'Y' to needed.

  cursor can create as CUR_GET_RAND_CARD or process c_suit select replace j_prc_sel_card (p_value out numbers, p_suit out number) c_value, (c_value, c_suit, jackson_card by dbms_random.value Select from the order) Where to get ROWNUM = 1 for the update; Open BEGINCUR_GET_RAND_CARD; Fetch CUR_GET_RAND_CARD in p_value, p_suit; Updated jackson card = 'y' where c_value = p_value and c_suit = p_suit; Close CUR_GET_RAND_CARD; End;  

Then I am trying to get the selected card and output which is in the form of the beginning. With it:

  set server output; DECLARE v_value number; V_suit number; BEGIN j_prc_sel_card (p_value = & gt; v_value, p_suit = & gt; v_suit); DBMS_OUTPUT.PUT_LINE (v_value); DBMS_OUTPUT.PUT_LINE (v_suit); End; / <>  

However I found an error in the title and it seems that my method of choosing a random card is preventing it from being updated thanks in advance!

There is a different opinion on the scenario here (I also addressed in my immediate problem).

Given that we are actually building a card handling program (as opposed to working with a test case for a business scenario) I moved column did not like. Updating table column is incorrect to mark the transient position. What happens when we want to play another game?

The following solution resolves this by making an array popular with all the cards in a random order upfront (shuffle). The cards are presented by taking the bus from the stack to the next entry. Package offers an option of running out of cards:. Or then throw a user-defined exception or just cycle through the deck

  space can make or package card_deck is no_more_cards exception, Pragma Apwad_init (no_more_cards, -20000); Process shuffle; Function deal_on (p_yn_continuous varchar2: = 'N') return card% rowtype; End card_deck; Change / replace the package body card or change the card_deck's table of type deck_t cards% rowtype; The_deck deck_t; Card counter pls_integer; Process reshuffle starts dbms_random.seed (to_number (to_char (sysdate, 'sssss'))); Select * Submit to Deck * from the card order via the Blooms_Rem.value. Card counter: = 0; End shuffle; Function Deal_on (p_yn_continuous varchar2: = 'N') Return Card% rowtype CardCountor is started: = card_counter + 1; If the card counter & gt; The_deck.count () Then if p_yn_continuous = 'N' then increase no_more_cords; Other card counters: = 1; end if; end if; Return the_deck (card_counter); End deal; End card_deck; /  

Here it is in action, do not use an open loop if you set the constant handling mode for y

  SQL & gt; Set server output on SQL and GT; SQL & gt; 2 my_card card declared% rowtype; 3 start 4 card_deck.shuffle; 5 Loop 6 Miccard: = card_deck.deal_one; 7dbms_output.put_line ('my card is' || my_card.c_suit || my_card.c_value); 8 end loop; 9 exception 10 when card_deck.no_more_cards then 11 dbms_output.put_line ('no more cards!'); 12 end; 13 / My card is yes my card is H7 my card is DJ My card is CQ My card is D9 my card s. No more cards! PL / SQL Process successfully complete SQL & gt;  

You think I'm not working with a full deck. You think that will not be the first;)


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -