使用 .sql 文件和 SQL*Plus 报告 SQL 语句成功/失败
我是同一个人问:
BEGIN/END 和 CREATE单个 .sql 文件中的表
无论如何,我们有几个通过 SQL*Plus 执行的 .sql 脚本。
这些脚本用于创建表、同义词、索引、视图等。
单个 .sql 文件中通常包含多个 CREATE 语句。
我们正在寻找一种方法来报告每个 CREATE 语句的通过/失败,以及失败时的错误消息。
Create table foo: Pass
Create index bar: Fail - Reason...
Create synonym foo_1: Pass etc.
目前,我们可以解析 SQL*Plus 输出,但是,其中包含很多无关的内容,并且像这样解析日志文件并不是最可靠的方法。
是否有更好的方法通过 SQLPlus 以编程方式检查每个 SQL 语句的返回状态以及错误消息(如果有)?这是 SQL Plus 可以实现的吗?
或者我是否需要编写某种类型的包装器(Bash、Python 等)?或者通过其他方式处理这一切?
干杯, 胜利者
I'm the same guy that asked:
BEGIN/END and CREATE Table in single .sql file
Anyhow, we have a several .sql scripts we're executing via SQL*Plus.
These scripts are used for creating tables, synonyms, indexes, views etc.
A single .sql file will usually have several CREATE statements inside them.
What we're looking for is a way to report pass/fail for each CREATE statement, as well as an error message if it failed.
Create table foo: Pass
Create index bar: Fail - Reason...
Create synonym foo_1: Pass etc.
Currently, we can parse the SQL*Plus output, however, this has a lot of extraneous stuff in it, and parsing a logfile like this isn't the most robust approach.
Is there a better way to programmatically check on the return status of each SQL statement via SQLPlus, and the error message, if any? Is that something achievable with SQLPlus?
Or do I need to write a wrapper of some sort (Bash, Python etc.)? Or handle this all via another way?
Cheers,
Victor
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
就我个人而言,我不喜欢将逻辑嵌入到 DDL 脚本中,除非绝对需要
(脚本很容易变得过于复杂,并且其操作难以预测)
我更喜欢扫描脚本输出是否有错误,例如:grep 查找字符串 ORA-
然后检查架构中是否有无效对象
Personally I don't like embedding logic into DDL scripts, unless absolutely needed
(the script can easily become overly complicated, and its action less predictable)
I prefer to scan the script output for errors e.g: grep for the string ORA-
Then check there are no invalid objects in the schema
您想在发生错误时继续执行 SQL 脚本,那么您应该从 PL/SQL 块内创建表和索引,因为 PL/SQL 具有良好的异常处理能力:
如果 发生错误时,可以使用以下 SQL*Plus 命令并在调用 SQL*plus 的脚本中进行错误处理:
If you want to continue with the SQL script when an error occurs, then you should create your tables and indices from within a PL/SQL block since PL/SQL has a decent exception handling:
If you want to end the current SQL script when an error occurs, you can use the following SQL*Plus command and do the error handling in the script that called SQL*plus: