1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

再帰CTEによるデータ投入

Posted at

再帰CTEを使用したINSERT文。性能確認用などで大量データを投入する際に使用する。他の方法と比べてないので、使い勝手はわからない。あと、適当に作ったので、改良の余地あり。

empテーブル
create table emp (
    empid char(10)
  , empname varchar2(50)
  , primary key(empid)
);
再帰CTEを使用したinsert文
insert into emp (empid, empname)
  with
    input(f, t) as (
      select 1, 10000 from dual
    )
  , seq(n) as (
      select f from input
      union all
      select n + 1 from seq where n + 1 <= (select t from input)
  )
  select lpad(n, 10, '0'), 'aaaa' from seq;
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?