d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Hey Trying To Find An Oracle Input All > Any Thoughts
Add Reply New Topic New Poll
Member
Posts: 14,631
Joined: Sep 14 2006
Gold: 575.56
Apr 21 2015 10:34pm
cant seem to figure out how to input multiple entries easily in oracle
unlike mysql where u just throw in additional entries and call it good
idk lmk
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Apr 22 2015 05:52pm
i have no idea what you're asking. use an INSERT statement. it can also import csv into a table.
Member
Posts: 14,631
Joined: Sep 14 2006
Gold: 575.56
May 4 2015 04:11pm
Quote (carteblanche @ Apr 22 2015 05:52pm)
i have no idea what you're asking. use an INSERT statement. it can also import csv into a table.


have been trying it in the environment and it doesnt work
found my answer though

INSERT ALL
INTO mytable (column1, column2, column_n) VALUES (expr1, expr2, expr_n)
INTO mytable (column1, column2, column_n) VALUES (expr1, expr2, expr_n)
INTO mytable (column1, column2, column_n) VALUES (expr1, expr2, expr_n)
SELECT * FROM dual;

for some reason there needs to be a select * from dual clause at the end
i dont really understand it but it has to be there you cant do without it, you still have to mark all your intos, its much easier with mysql

mysql was much easier just insert ... into ... values (), (), ()
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
May 4 2015 04:31pm
Quote (Ideophobe @ May 4 2015 06:11pm)
have been trying it in the environment and it doesnt work
found my answer though

INSERT ALL
INTO mytable (column1, column2, column_n) VALUES (expr1, expr2, expr_n)
INTO mytable (column1, column2, column_n) VALUES (expr1, expr2, expr_n)
INTO mytable (column1, column2, column_n) VALUES (expr1, expr2, expr_n)
SELECT * FROM dual;

for some reason there needs to be a select * from dual clause at the end
i dont really understand it but it has to be there you cant do without it, you still have to mark all your intos, its much easier with mysql

mysql was much easier just insert ... into ... values (), (), ()


you misunderstood the point of the command. its intention isn't to act like INSERT...VALUES, but rather INSERT...SELECT for multiple tables.

suppose you wanted to copy all the data from one table and put it in another. you would do it like so:
Code
insert into backup_table(...) select * from original_table;


now what if you wanted to copy all the data from one table and put it into multiple tables? this is one way of doing it:
Code
insert into backup_table1(...) select * from original_table;
insert into backup_table2(...) select * from original_table;
insert into backup_table3(...) select * from original_table;


however, you'll notice that you just did a full table scan 3 times on the same table. is there a way to insert the same data into multiple tables without doing a full table scan each time? enter INSERT ALL.

Code
insert all
into backup_table1
into backup_table2
into backup_table3
select * from original_table


going back to your example, since you don't want to do INSERT...SELECT but rather INSERT...VALUES, you need to select a single row and fill it with constants, eg INSERT...SELECT * from dual. which is what you did.

personally, i've never used it since i've never needed this scenario. i'm not sure i understand if there is any benefit to using it with constants as opposed to multiple INSERT statements. personally, i'd just write multiple insert statements. it's cleaner, clearer, can be used with any dbms, better used with prepared statements, and i'm guessing it's easier to find errors.

This post was edited by carteblanche on May 4 2015 04:46pm
Member
Posts: 14,631
Joined: Sep 14 2006
Gold: 575.56
May 5 2015 01:44am
the goal was to insert values for 3 entries into 1 table with a single command, yes there are a number of other things you can do with insert select but i just wanted to do something simple
the syntax i posted up there works I just dont understand why with oracle compared to others i have to have a select statement in there and repeat your desired table/fields over and over it's clutter

with most sqls you can just
Code
INSERT INTO Table ( Column1, Column2, Column_n )
VALUES
( expr1, expr2, expr_n),
( expr1, expr2, expr_n),
( expr1, expr2, expr_n);

which seems nice easy and intuitive but Oracle wont let it happen instead it forces you down the more complicated select path for any insert with multiple entries
idk just one of the things i gotta give up with Oracle i guess, DECODE and GROUPING are cool and the joins are nice but the insert thing is a real buzzkill

This post was edited by Ideophobe on May 5 2015 01:56am
Member
Posts: 11,637
Joined: Feb 2 2004
Gold: 434.84
May 5 2015 06:57am
Quote (Ideophobe @ May 5 2015 02:44am)
the goal was to insert values for 3 entries into 1 table with a single command, yes there are a number of other things you can do with insert select but i just wanted to do something simple
the syntax i posted up there works I just dont understand why with oracle compared to others i have to have a select statement in there and repeat your desired table/fields over and over it's clutter

with most sqls you can just
Code
INSERT INTO Table ( Column1, Column2, Column_n )
VALUES
( expr1, expr2, expr_n),
( expr1, expr2, expr_n),
( expr1, expr2, expr_n);

which seems nice easy and intuitive but Oracle wont let it happen instead it forces you down the more complicated select path for any insert with multiple entries
idk just one of the things i gotta give up with Oracle i guess, DECODE and GROUPING are cool and the joins are nice but the insert thing is a real buzzkill


Welcome to Oracle. You'll be disappointed more often than not. The worst thing I ever had to do was get my OCA cert.
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll