oracle sqlplus 打印运行语句
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16466127/
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
sqlplus print running statement
提问by Younes
Is there a way where sqlplus can print what statement it executed. I mean I have some .sql files that I run in a bash script. I need to know when I read the log file which statement sqlplus ran.
有没有办法让 sqlplus 可以打印它执行的语句。我的意思是我有一些在 bash 脚本中运行的 .sql 文件。当我阅读日志文件时,我需要知道 sqlplus 运行了哪个语句。
Example: Say I have this test.sql file:
示例:假设我有这个 test.sql 文件:
set timing on
create table foo (a varchar2(10));
create table bar (b varchar2(10));
exit
When I check the log I get this:
当我检查日志时,我得到了这个:
Table created.
Elapsed: 00:00:00.02
Table created.
Elapsed: 00:00:00.01
Which is not informative. Is there a way where I can get output like this:
这不是信息性的。有没有办法让我得到这样的输出:
Table foo created.
Elapsed: 00:00:00.02
Table bar created.
Elapsed: 00:00:00.01
Or even like this:
或者甚至像这样:
create table foo (a varchar2(10));
Table created.
Elapsed: 00:00:00.02
create table bar (b varchar2(10));
Table created.
Elapsed: 00:00:00.01
I know I can use PROMPT before each statement but I have big sql scripts and it would be tedious to write PROMPT before each statement.
我知道我可以在每个语句之前使用 PROMPT,但是我有很大的 sql 脚本,在每个语句之前编写 PROMPT 会很乏味。
EDIT:
编辑:
For Allan's solution to always work (i.e. using "set echo on"), you should avoid the following:
为了让艾伦的解决方案始终有效(即使用“ set echo on”),您应该避免以下情况:
1) Don't use the -S option with sqlplus because this will suppress the display of echoing of commands.
1) 不要在 sqlplus 中使用 -S 选项,因为这会抑制命令回显的显示。
2) Don't "cat" your script to sqlplus like this:
2)不要像这样将你的脚本“cat”到sqlplus:
cat test.sql | sqlplus scott/tiger@orcl
回答by Allan
The command you're looking for is SET ECHO ON
, which will repeat the each statement that is issued.
您要查找的命令是SET ECHO ON
,它将重复发出的每个语句。
回答by David Aldridge
If you need to know the exact creation time for the objects you could query DBA_OBJECTS or ALL_OBJECTS for the CREATED column.
如果您需要知道对象的确切创建时间,您可以查询 DBA_OBJECTS 或 ALL_OBJECTS 以获取 CREATED 列。