【发布时间】:2020-11-30 02:28:09
【问题描述】:
我使用 Oracle SQL Developer 运行以下 SQL 脚本。我不知道为什么它会创建两个假脱机文件,并且它还会在 Oracle SQL Developer 控制台中显示它不应该的整个操作。可能是因为每个删除语句都有SET FEEDBACK ON 和SET FEEDBACK OFF。
它会创建两个文件,并且只有在有一些记录需要删除时才会在脚本输出中显示所有内容。
脚本的调用
@"C:\RM.sql"
脚本
SET PAGES 0
SET LINESIZE 10000
SET TRIMS ON
SET ECHO OFF
SET HEADING ON
SET VERIFY OFF
SET FEEDBACK OFF
SET TERMOUT OFF
SET SERVEROUTPUT on size 1000000
SET TIMING OFF
SET COLSEP '|'
alter session set NLS_DATE_FORMAT = 'dd.mm.yyyy hh24:mi:ss';
whenever oserror exit -1
whenever sqlerror exit -2
-- The current timestamps into 'times' variable
column times new_value times noprint
select to_char(sysdate, 'YYYYMMDD_HH24MISS') times from DUAL;
-- variables definition
define output_file="C:\temp\filename_×..log"
-- echo some text to the standard output
SET TERMOUT ON
PROMPT
PROMPT "The script counts and reports the records to be deleted..."
PROMPT
SET TERMOUT OFF
-- write the results to the 'output_file' file
spool &output_file
PROMPT
PROMPT "BEGIN------------------------------"
PROMPT "delete from the_table1"
select 'Total records BEFORE delete: ' || count (*) as count_records from the_table1;
SET FEEDBACK ON
PROMPT "Actual deletion of records..."
delete from the_table1;
commit;
SET FEEDBACK OFF
PROMPT "END------------------------------"
PROMPT
PROMPT "BEGIN------------------------------"
PROMPT "delete from the_table2"
select 'Total records BEFORE delete: ' || count (*) as count_records from the_table2;
SET FEEDBACK ON
PROMPT "Actual deletion of records..."
delete from the_table2;
commit;
SET FEEDBACK OFF
PROMPT "END------------------------------"
PROMPT
PROMPT "The script completed..."
SPOOL OFF
SET TERMOUT ON
PROMPT
PROMPT "&output_file has been successfully ended."
PROMPT
PROMPT
EXIT
;
【问题讨论】:
-
我刚刚使用 SQL Developer 版本 20.2 运行了这个场景,并且只有一个日志文件被 SPOOLed/created
-
这里一样,只有一个文件。顺便说一句,如果你要删除整个表,你不应该截断它吗?
-
@thatjeffsmith 感谢您的反馈。我不知道为什么我现在不能重现它。
-
@RobertoHernandez 感谢您的反馈。我不知道为什么我不能重现它。
-
@Sherzad 您能否在您的问题中提供脚本执行的输出,表明它实际上正在创建两个假脱机文件?
标签: oracle oracle-sqldeveloper sqlplus sql-scripts spool