oracle db2 sql 脚本文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1102763/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
db2 sql script file
提问by smauel
I have an oracle script that I am trying to convert to valid db2 syntax. Within this sql file I have various calls to other sql files passing in a parameter using the '@' syntax.
我有一个 oracle 脚本,我试图将其转换为有效的 db2 语法。在这个 sql 文件中,我对其他 sql 文件进行了各种调用,这些文件使用“@”语法传入了一个参数。
e.g.
例如
@script1 param1
@script2 param2
Can anyone help me with valid db2 equivalent statements? Is there an equivalent run command in db2? is it possible to pass parameters to a sql script in db2?
任何人都可以帮助我提供有效的 db2 等效语句吗?db2 中是否有等效的运行命令?是否可以将参数传递给 db2 中的 sql 脚本?
thanks,
谢谢,
smauel
斯马厄尔
回答by Michael Sharek
The thing you are after is the DB2 Command Line Processor (CLP).
您所追求的是DB2 命令行处理器 (CLP)。
If you want to execute a script, you would execute in the CLP:
如果要执行脚本,则应在 CLP 中执行:
db2 -vtf script1
-f tells the CLP to run command input from the given file.
-f 告诉 CLP 运行来自给定文件的命令输入。
Here's the full list of options.
Unfortunately db2 doesn't support passing parameters to a script. You would have to combine your db2 -vtf commands with other scripting commands (such as sed) to generate the scripts for you, as in this example.
不幸的是,db2 不支持将参数传递给脚本。您必须将 db2 -vtf 命令与其他脚本命令(例如 sed)结合起来为您生成脚本,如本例所示。
回答by Abhishek
1) place the filename.sqlfile in SQLLIB/BIN
1) 将filename.sql文件放在 SQLLIB/BIN 中
2) run db2cmd
2) 运行 db2cmd
3) execute this to connect to the required db
3)执行此操作以连接到所需的数据库
db2 connect to *dbname* user *userid* using *password*
4) excute this command
4)执行这个命令
db2 -vtf *filename.sql*
This should execute the sql statements in the file one by one. The sql statements must be ending with a semicolon
这应该将文件中的sql语句一一执行。sql 语句必须以分号结尾
回答by Peter Schuetze
There is an easier way for passing in parameters, that works fine for us (it might not work with (complex) multiline sql statements).
有一种更简单的方法来传递参数,这对我们来说很好用(它可能不适用于(复杂的)多行 sql 语句)。
Convert your sql-script into a shell script by adding 'db2 ' at the beginning of each line. Than you can use the standard variable replacement syntax from your shell in your scripts.
通过在每行的开头添加“db2”,将您的 sql 脚本转换为 shell 脚本。您可以在脚本中使用 shell 中的标准变量替换语法。
so instead of
所以而不是
insert ...
update ...
you will have
你将会有
db2 insert ...
db2 update ...