creating SQL script

2019-09-18 10:29发布

问题:

I'm trying to create an SQL script to automatize inserting of values into a table.

I have a table table1 with 2 columns: key, value.

I want to insert a few rows:

INSERT INTO table1 (key, value) VALUES ("tomato1","random_value_1")
INSERT INTO table1 (key, value) VALUES ("tomato2","random_value_2")
INSERT INTO table1 (key, value) VALUES ("tomato3","random_value_3")
INSERT INTO table1 (key, value) VALUES ("tomato4","random_value_4")

How can I put this into a shell script that I can execute from command line.

Thanks

回答1:

save as a file with .sql extension.

then run from the command line with a sql connection tool like SQLPLus (you don't indicate which database you are on)



回答2:

You should also combine inserts to the same table into one, as it is much faster, like so:

INSERT INTO table1 
(key, value) VALUES 
("tomato1","$1"),
("tomato2","$2"),
("tomato3","$3"),
("tomato4","$4")


标签: oracle shell