【问题标题】:Execute SQL Procedure in Oracle Database with batch file使用批处理文件在 Oracle 数据库中执行 SQL 过程
【发布时间】:2018-11-22 14:54:03
【问题描述】:

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

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

END;
/
exit;
!

。只能连接数据库,不能执行查询。

【问题讨论】:

    标签: batch-file oracle11g sqlplus


    【解决方案1】:

    我会将 SQL/SQL*Plus 命令分离到一个单独的脚本中:

    myscript.sql:

    set heading off
    set feedback off
    BEGIN
    AML.DO_ACCOUNT_AML() ;
    COMMIT
    
    END;
    /
    

    让批处理脚本只处理控制流:

    myscript.bat:

    echo off
    sqlplus username/password@databasename @myscript.sql
    !
    

    【讨论】:

      【解决方案2】:

      两个步骤(正如您已经说过的):批处理脚本 + 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:\>
      

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

      【讨论】:

        猜你喜欢
        • 2012-12-26
        • 2021-12-28
        • 1970-01-01
        • 2012-10-10
        • 2013-03-01
        • 2019-11-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多