1. 现在PL/SQL 脚本中有个参数,是通过 ACCEPT 指令交互式得到的,我希望能直接从命令行调用这个 SQL 文件并且把这个参数也从命令行指定它。如何做到这点?另外.
2. sqlplus 脚本中,能像 C 语言 system("dir") 那样调用一个操作系统的程序吗?

解决方案 »

  1.   

    shell下是可以的,cmd下没有研究过,估计也行sqlplus不能调用程序,但是能调用SQL脚本,也能用host命令切换到操作系统环境下执行程序
      

  2.   

    用 sqlplus 专用的自定义函数间接地调用操作系统命令(比如打印一下日志文件)吗?
    我看到这样一行代码,$print run$dat:hp.font16l/que=lta8 看上去是要打印一个东西,似乎还指定的参数送到某台打印机或某个打印队列上,因为我还看到其它 /que=lta3 之类的代码。那个参数的问题,如果不修改现有代码就能做到是最好的,实在不行就把这部分换成 & 的参数。能说说在 linux 或 unix 这些 Shell 脚本中是如何做到把参数在命令行事先就传递过去了而不用在 ACCEPT 指令执行时暂停那里等待吗?我们的服务器很可能是 linux/unix,因为我们现在需要批量执行,如果模拟交互式的程序就需要我们读取控制台输出消息来判断是否需要参数,这会比较麻烦。
      

  3.   

    1. 可以将ACCEPT 替换为'@1', '@2'...:
    19:52:21 C:\temp>cat test.pls
    DECLARE
      v_log_path     VARCHAR2(50);
      v_log_filename VARCHAR2(20);
    BEGIN
      v_log_path     := '&1';
      v_log_filename := '&2';
      dbms_output.put_line(v_log_path || '/' || v_log_filename);
    END;
    /19:52:30 C:\temp>sqlplus  xxx/xx@xxSQL*Plus: Release 11.2.0.1.0 Production on Thu Jan 17 19:52:38 2013Copyright (c) 1982, 2010, Oracle.  All rights reserved.
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    With the Partitioning, Oracle Label Security, OLAP, Data Mining,
    Oracle Database Vault and Real Application Testing optionsSQL> start test.pls 'c:\temp' 'test.log'
    old   5:   v_log_path     := '&1';
    new   5:   v_log_path     := 'c:\temp';
    old   6:   v_log_filename := '&2';
    new   6:   v_log_filename := 'test.log';PL/SQL procedure successfully completed.2. 可以使用$<command>来执行windows命令,比如
    SQL> $hostname
    machinename
    如果此程序是JAVA,可以定一个存储过程调用JAVA,然后sqlplus里面调用此存储过程。
      

  4.   

    问题1:举例select * from dual where 1=&a;   &a为参数,即参数前加一个&符号
    问题2:可通过java编写存储过程实现调用...