首页 > 解决方案 > 使用批处理文件在 Oracle 数据库中执行 SQL 过程

问题描述

我创建了一个 .bat 文件来执行这些行的过程:

echo off
sqlplus username/password@databasename
set heading off
set feedback off
BEGIN
AML.DO_ACCOUNT_AML() ;
COMMIT

END;
/
exit;
!

. 它只能连接到数据库,但不能执行查询。

标签: batch-fileoracle11gsqlplus

解决方案


两个步骤(正如您已经被告知的那样):批处理脚本 + SQL 脚本。

批处理脚本

sqlplus scott/tiger@orcl @run_proc.sql

SQL 脚本 (run_proc.sql)

set serveroutput on
begin
  p_test;
end;
/
exit

存储过程

create or replace procedure p_test is
begin
  dbms_output.put_line('Hello!');
end;
/

在操作系统命令提示符下运行runme.bat会导致:

M:\>runme

M:\>sqlplus scott/tiger@orcl @run_proc.sql

SQL*Plus: Release 11.2.0.1.0 Production on Sri Lip 13 11:28:00 2018

Copyright (c) 1982, 2010, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

hello

PL/SQL procedure successfully completed.

Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

M:\>

显然,它有效。现在,您可以使用不同的设置(回声、反馈等),但是 - 通常,就是这样。


推荐阅读