简体   繁体   English

避免在Oracle SQL中假脱机时将错误复制到CSV中

[英]Avoiding Errors getting copied into CSV while spooling out in Oracle SQL

I have a SQL code which spools out data into a .csv file from Oracle databases. 我有一个SQL代码,可将数据从Oracle数据库中缓存到.csv文件中。

set echo off
set feedback off
set linesize 1000
set pagesize 0
set sqlprompt ''
set trimspool on
set verify off
spool test.csv
    /*Code Part*/
/
spool off

The problem is that, if at all any error occurs (eg: resource busy issue) while executing code part, those error messages are getting copied into .csv file along with the spooled data. 问题是,如果在执行代码部分时发生任何错误(例如:资源繁忙问题),这些错误消息将与假脱机数据一起复制到.csv文件中。 Is there any way to avoid it? 有什么办法可以避免呢?

It would be much more helpful if some one suggests me a way to redirect these error messages to a .txt file (I dont know if it is possible or not). 如果有人向我建议一种将这些错误消息重定向到.txt文件的方式(我不知道是否可能),它将大有帮助。

Thanks! 谢谢!

You may want to look into using the UTL_FILE package to create the file you want rather than counting on SQL*Plus to redirect your output. 您可能需要研究使用UTL_FILE包来创建所需的文件,而不是依靠SQL * Plus来重定向输出。 While this would perhaps require some rewriting on your part you'd end up with better control of what is being written. 虽然这可能需要您进行一些重写,但最终还是可以更好地控制所写内容。

Another option would be to filter the output file to eliminate . 另一个选择是过滤输出文件以消除。 For example, if the lines you don't want to see all start with "ORA-" you might be able to use something like the grep command: 例如,如果您不想看到的所有行都以“ ORA-”开头,则可以使用类似grep命令的代码:

grep -v ^"ORA-" test.csv

Or you might have to use something like sed or awk if your filtering requirements are more complicated. 或者,如果您的过滤要求更加复杂,则可能必须使用sedawk类的东西。

Share and enjoy. 分享并享受。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM