sailaja
sailaja

Reputation: 429

How to Insert a value multiple times in oracle database?

I want to Insert values multiple times like, I have PartNo and Quantity if I enter PartNo as Fibre and Qty = 3 then It should fill in 5 times as:

PartNo Inventory_Qty
Fibre   1
Fibre   1
Fibre   1

Please help me how to write a query for this.

Upvotes: 0

Views: 726

Answers (2)

Jean-Charles
Jean-Charles

Reputation: 1720

In only one sql command:

INSERT INTO table1 ('PartNo', 'Inventory_Qty')
    SELECT 'Fibre',   1 FROM DUAL
    UNION ALL
    SELECT 'Fibre',   1 FROM DUAL
    UNION ALL
    SELECT 'Fibre',   1 FROM DUAL;

or differently (but not supported by Oracle, thanks Lukas Eder)

INSERT INTO table1 ('PartNo', 'Inventory_Qty')
VALUES ('Fibre',   1),
('Fibre',   1),
('Fibre',   1);

Upvotes: 2

René Nyffenegger
René Nyffenegger

Reputation: 40499

With a table such as

create table tq84_insert_test (
  partNo        varchar2(20),
  inventory_qty number(4)
);

you migh try

insert into tq84_insert_test 
select
  'Fibre', 1
from
  dual
connect by rownum <= 3;

Since I'm not sure if you want to insert 3 or 5 records, I assumed 3. But you might want to change the 3 in the insert statement accordingly.

Upvotes: 3

Related Questions