Oracle產生100萬條測試資料的方法__Oracle

來源:互聯網
上載者:User

Oracle產生一百萬測試資料的方法如下:

方法一:建立一個表,並同時添加1000000條資料,代碼:

create table TestTable as select rownum as id,               to_char(sysdate + rownum/24/3600, 'yyyy-mm-dd hh24:mi:ss') as inc_datetime,               trunc(dbms_random.value(0, 100)) as random_id,               dbms_random.string('x', 20) random_string          from dual        connect by level <= 1000000;

方法二:在建立表後,原來表的基礎上追加記錄,比如在方法一建立的TestTable表中追加1000000條資料,代碼:

insert into TestTable  (ID, INC_DATETIME,RANDOM_ID,RANDOM_STRING)  select rownum as id,         to_char(sysdate + rownum / 24 / 3600, 'yyyy-mm-dd hh24:mi:ss') as inc_datetime,         trunc(dbms_random.value(0, 100)) as random_id,         dbms_random.string('x', 20) random_string    from dual  connect by level <= 1000000;

上面SQL是利用了Oracle資料庫文法的幾個實用小技巧實現的:
1、利用Oracle特有的“connect by”樹形串連文法產生測試記錄,“level <= 10”表示要產生10記錄;
2、利用rownum虛擬列產生遞增的整數資料;
3、利用sysdate函數加一些簡單運算來產生日期資料,本例中是每條記錄的時間加1秒;
4、利用dbms_random.value函數產生隨機的數值型資料,本例中是產生0到100之間的隨機整數;
5、利用dbms_random.string函數產生隨機的字元型資料,本例中是產生長度為20的隨機字串,字串中可以包括字元或數字。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.