Using Oracle 12c, I have, for example, 5 rows with values 1,2,3,4,5 in a PK column in one table TABLEA
. I would like to insert into another table TABLEB
the values but 3 times. So TABLE would have 15 rows with values 1,1,1,2,2,2,3,3,3,4,4,4,5,5,5 after the insert. How can I achieve this?
I'm trying to create a script that will insert values from TABLEA
to TABLEB
if they don't already exist there. Currently I am manually inserting into TABLEB
each value from TABLEA
3 times.
You can use cross join
. The query would look something like this:
insert into t(pk)
select pk
from table t2 cross join
(select 1 as n from dual union all select 2 from dual union all select 3 from dual
) n;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.