creating SQL script

2019-09-18 10:44发布

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

标签: oracle shell
2条回答
别忘想泡老子
2楼-- · 2019-09-18 11:07

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)

查看更多
老娘就宠你
3楼-- · 2019-09-18 11:26

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")
查看更多
登录 后发表回答