创建SQL脚本

时间:2012-06-19 18:47:33

标签: oracle shell

我正在尝试创建一个SQL脚本来自动将值插入表中。

我有一个包含2列的表table1:key,value。

我想插入几行:

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")

如何将它放入我可以从命令行执行的shell脚本中。

由于

2 个答案:

答案 0 :(得分:2)

另存为扩展名为.sql的文件。

然后使用SQLPLus之类的SQL连接工具从命令行运行(您没有指明您所在的数据库)

答案 1 :(得分:2)

您还应该将同一个表中的插入组合为一个,因为它更快,如下所示:

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