如何使用PL SQL更改SqlPlus结果的输出?

时间:2015-03-13 08:33:12

标签: sql shell plsql oracle-sqldeveloper sqlplus

我有一个包含plsql代码的脚本。代码的输出非常复杂。 代码在这里:



#!/usr/bin/ksh
$ORACLE_HOME/bin/sqlplus<<EOF
x/xx@xxx
set serveroutput on
set sqlnumber off
set sqlblanklines off
set feedback off
DECLARE
is_found_rec boolean := false; 
CURSOR c1
IS
select name from rdsolucadm.BPM_T_SEMAPHORE where value in  ('0') and description like 'R%'; 
BEGIN
    FOR r1 IN c1
    LOOP  
        is_found_rec := true;
        update  RDSOLUCADM.BPM_T_SEMAPHORE set value ='2' where value in ('0') and description like 'R%';
        commit;
        dbms_output.put_line ('BPM_T_SEMAPHORE table is updated.');
    END LOOP; 
    if not is_found_rec then 
        dbms_output.put_line ('BPM_T_SEMAPHORE table is NOT updated!!!');
    end if;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line(SubStr('Error '||TO_CHAR(SQLCODE)||': '||SQLERRM, 1, 255));
RAISE;
END;
/
exit
EOF
&#13;
&#13;
&#13;

  

结果如下:

     

连接到:Oracle Database 11g企业版发行版   11.2.0.3.0 - 64位生产,具有分区,真实应用集群,自动存储管理,OLAP,数据挖掘和实时   应用程序测试选项

     

SQL&GT; SQL&GT; SQL&GT; SQL&GT; SQL&GT; SQL&GT; SQL&GT; SQL&GT; SQL&GT; SQL&GT; SQL&GT; SQL&GT; SQL&GT; SQL&GT;   SQL&GT; SQL&GT; SQL&GT; SQL&GT; SQL&GT; SQL&GT; SQL&GT; SQL&GT; SQL&GT; SQL&GT; SQL&GT; SQL&GT;   BPM_T_SEMAPHORE表未更新!!!

     

SQL&GT;与Oracle断开连接   数据库11g企业版11.2.0.3.0版 - 64位生产   使用分区,Real Application Clusters,自动存储   管理,OLAP,数据挖掘和实际应用程序测试选项

我不想看到很多&#34; SQL&gt; SQL&GT; SQL&GT; SQL&GT; SQL&GT; .....&#34; 如何设置此属性?你能帮帮我吗?

谢谢, 最诚挚的问候

1 个答案:

答案 0 :(得分:0)

您在-s的通话中错过了sqlplus标记 示例代码:

oracle@***:/home/oracle/testing> cat test.sh
$ORACLE_HOME/bin/sqlplus -s<<EOF
XXX/XXX
set serveroutput on
set sqlnumber off
set sqlblanklines off
set feedback off
BEGIN
        dbms_output.put_line('testing');
END;
/
exit
EOF

没有-s标志的示例输出:

oracle@***:/home/oracle/testing> sh test.sh

SQL*Plus: Release 11.2.0.3.0 Production on Fri Mar 13 08:12:21 2015

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

Enter user-name:
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> testing
SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

-s标志示例:

oracle@XXX:/home/oracle/testing> sh test.sh
testing