写了个shell脚本(testdb.sh)如下:
#!/bin/csh
sqlplus hbjs/hbjs@js_test_10gr2 <<!
select count(*) from dps_module_log where FILE_NAME like 'B%.791' and total_count=0;
!
运行后输出为
SQL*Plus: Release 9.2.0.1.0 - Production on Tue Oct 11 16:23:19 2011Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, Data Mining and Real Application Testing optionsSQL> 
  COUNT(*)
----------
      1130SQL> Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, Data Mining and Real Application Testing options我只想要1130这个值 希望运行脚本后返回值为1130,该怎么做!!!!
不能借助其他程序或脚本。只运行testdb.sh后便得到数据值

解决方案 »

  1.   

    select 语句之前加以下几个设置set pagesize 0;
    set linesize 1024;
    set feedback off;
      

  2.   

    还有,sqlplus -l -s user/passwd
      

  3.   


    oracle@mns101:~/shell> cat test.sh 
    #!/bin/cshsqlplus -l -s scott/tiger@ora11 << !
        set pagesize 0;
        set linesize 1024;
        set feedback off;
        select * from dual;
        exit;
    !
    oracle@mns101:~/shell> csh test.sh 
    X
    oracle@mns101:~/shell>
      

  4.   

    slqplus -l -s $1/$2@$3 <<!
    set pagesize 0;
    select count(*) from tableName;
    !
      

  5.   

    #!/bin/bshsqlplus -l -s sbs/sbs@topprod << !
    set pagesize 0;
    set linesize 1024;
    set feedback off;
    select sysdate from dual;
    exit;
    !bsh test.sh--result:
    2011/11/12