【问题标题】:SQLPLUS command line with Windows batch file带有 Windows 批处理文件的 SQLPLUS 命令行
【发布时间】:2023-03-28 04:30:02
【问题描述】:

我想创建一个批处理文件,它将打开 SQLPLUS [CLI] 并执行一些存储的 sql 文件并将输出存储到文本文件。

所以我创建了这个批处理文件 [它不起作用]。
这些 SQL 文件包含从表中返回最大数量的 SQL。

sqlplus scott/tiger@DB
@sql1.sql>data1.txt
@sql2.sql>data2.txt

问题是打开SQLPLUS后不执行SQL文件

  • Windows XP
  • 甲骨文 9i

【问题讨论】:

    标签: batch-file sqlplus oracle9i


    【解决方案1】:

    为了您和社区其他人的信息,我在 dos 文件中使用了这个命令行:

    sqlplus.exe SIEBEL/mypass@mydb @D:\App\Siebel\EIM\sql\my_sql_command.sql
    

    输出是:

    SQL*Plus: Release 11.2.0.1.0 Production on Mar. Sept. 13 11:53:52 2016
    
    Copyright (c) 1982, 2010, Oracle.  All rights reserved.
    
    ERROR:
    ORA-12154: TNS : .....
    

    其实我是在命令行出错....

    sqlplus.exe SIEBEL/mypass@mydb**%** @D:\App\Siebel\EIM\sql\my_sql_command.sql
    

    【讨论】:

      【解决方案2】:

      原生 Sql*plus 假脱机怎么样?

      运行.bat:

      sqlplus hr/hr@sandbox @d:\run.sql
      

      运行.sql:

      spool d:\run.log
      set echo on 
      
      select * from dual
      /
      exit
      

      运行日志:

      01:50:20 HR@sandbox> 
      01:50:20 HR@sandbox> select * from dual
      01:50:20   2  /
      
      D
      -
      X
      
      Elapsed: 00:00:00.00
      01:50:21 HR@sandbox> exit
      

      【讨论】:

        【解决方案3】:
        SET ORACLE_SID=<YOUR SID HERE>
        
        sqlplus scott/tiger@DB < sql1.sql > data1.txt
        sqlplus scott/tiger@DB < sql2.sql > data2.txt
        

        【讨论】:

        • ORACLE_SID。如果您的系统上有一个实例,则可以跳过这一行。
        • 哎呀,没用。仅启动 SQLPLUS 但未能传递参数!
        • data1.txt 和 data2.txt 是干什么用的?
        猜你喜欢
        • 2011-04-28
        • 2010-11-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-07-14
        • 1970-01-01
        • 1970-01-01
        • 2015-09-12
        相关资源
        最近更新 更多