如何将 PL/SQL .sql 文件转换为 SQL*PLUS,以便它可以与 Windows 任务计划程序一起运行
Posted
技术标签:
【中文标题】如何将 PL/SQL .sql 文件转换为 SQL*PLUS,以便它可以与 Windows 任务计划程序一起运行【英文标题】:How to covert PL/SQL .sql file to SQL*PLUS so it can be run with Windows Task Scheduler 【发布时间】:2014-10-24 13:27:46 【问题描述】:我正在尝试将 CONDITION_TEST.sql 文件添加到 Windows 任务计划程序,以便它每天自动运行。
我创建了一个包含以下文本的 .bat 文件: sqlplus userid/password@csdpro @C:\Users\userid\Desktop\HCR_Datamart_Recon\CONDITION_TEST.sql 回显提交; |用户名/密码$@csdpro
CONDITION_TEST.sql 文件是使用 PL/SQL 创建的。现在以@ 开头的行曾经是“select from”语句。我将该块保存为单独的 .sql 文件。
DECLARE
v_chkt_dm date;v_chks_dm number;v_chkt_un date; v_dm_fix varchar2(20000);
-----------------------------------------------------------------------------------
BEGIN
Select /*+parallel (a,4)*/ trunc(max(a.action_timestamp))
into v_chkt_dm
from hcr_dm.hcr_dm_fact a;
Select /*+parallel (a,4)*/ count(distinct a.src_table)
into v_chks_dm
from hcr_dm.hcr_dm_fact a;
Select /*+parallel (b,4)*/ trunc(max(b.action_timestamp))
into v_chkt_un
from hcr_sandbox.hcrdm_the_big_union b;
-----------------------------------------------------------------------------------
If v_chkt_un < trunc(sysdate) then
If v_chkt_dm = trunc(sysdate) and v_chks_dm = 9 then
execute immediate 'truncate table HCR_SANDBOX.HCR_DM_FIX';
commit;
Else
execute immediate 'truncate table HCR_SANDBOX.HCR_DM_FIXED_SUM';
commit;
END IF;
Else
@V:\AccountingOperations\Statutory\ReneeGuo\AUTO_BIG_UNION\DM_FIX.sql;
commit;
END IF;
END;
运行调度程序后,我得到了这样的屏幕(我在下面输入了屏幕结果)。看到数字167后任务停止运行,不知道是什么意思。然后,如果我按 ENTER,它将在下一行创建一个新整数。
我没有经常处理 SQL*plus,所以不确定出了什么问题。谁能帮我这个?谢谢!
c:\Windows\system32>sqlplus userid..... CONDITION_TEST.sql
SQL*Plus: Release 11.2.0.1.0 Production on Fri Oct 24 09:10:35 2014
Copyright <c> 1982, 2010, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Prodution With the Partitioning,
OLAP, Data Mining and Real Application Testing options
167
168
169 _
【问题讨论】:
【参考方案1】:将这两行添加到 .sql 脚本的底部:
/
quit;
正斜杠命令执行缓冲区中的内容。来自:http://docs.oracle.com/cd/E11882_01/server.112/e16605/toc.htm#i765097
/ (slash)
Executes the most recently executed SQL command or PL/SQL block which is
stored in the SQL buffer. Does not list the command. Use slash (/) at the
command prompt or line number prompt in SQL*Plus command line. The buffer
has no command history and does not record SQL*Plus commands.
quit 命令是必需的,否则当脚本完成时,它会将您留在 sqlplus 中。此外,如果您使用 -S for silent 选项调用 sqlplus,您将不会得到那么多多余的输出。
哦,你最好更改密码。呵呵
【讨论】:
感谢您的帮助!添加 / 后似乎可以正常工作,但目前屏幕只显示“PL/SQL 过程已成功完成”。我怎样才能让它说出每个步骤的状态?就像在 PL/SQL 中一样,我可以在不同的地方使用 dbms_output.put_line 来表示“第一个条件满足”、“第一个条件失败”等。 阅读 SQL*Plus 的“SET”命令。您至少需要“设置服务器输出”。以上是关于如何将 PL/SQL .sql 文件转换为 SQL*PLUS,以便它可以与 Windows 任务计划程序一起运行的主要内容,如果未能解决你的问题,请参考以下文章
如何使用非默认 NLS_NUMERIC_CHARACTERS 在 Oracle PL/SQL 中有效地将文本转换为数字?