PL/SQLランダム値の生成

2012年6月13日 Posted by PURGE

set serveroutput on
DECLARE

  CURSOR ids is   
    select customer_id 
      from customer_mst;

  customers ids%ROWTYPE;
  rnd NUMBER(2);
BEGIN
  open corp2_ids;
    LOOP
      FETCH ids INTO customers;
        --50~95の整数ランダム値を返す
        rnd := trunc(DBMS_RANDOM.VALUE(50,95), 0);
        DBMS_OUTPUT.PUT_LINE(rnd);
      update customer_mst
         set score = rnd
       where customer_id = customers.customer_id;

      EXIT WHEN ids%NOTFOUND;
    END LOOP;
  commit;
  close ids;
END;
/

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です