执行脚本的命令在上一节已经讲过,再也不重复。html
sqlplus user/password@ip:port/servicename @/path/sqltest.sql;
sqltest的内容及注释:sql
--这个WHENEVER表示出现错误以后,再也不继续执行,还会尽可能回滚 WHENEVER SQLERROR EXIT SQL.SQLCODE ROLLBACK --select 'OK' from duabbl; --select 'OK' from duiaaal; --输出执行的语句 set echo on; --将执行结果输出到文件 spool /tmp/spool.txt; select 'OK' from dual; --创建一个空的无害的存储过程 create or replace procedure ADisabledSP(timeStamp number, tableName varchar2) is begin if timeStamp<0 then --该条件永远没法成立,且使用了输入参数timeStamp dbms_output.put_line('We are going to operate on table ' || tableName); --使用了输入参数tableName end if; end; --这个/在命令行中执行是必须的,表示执行,否则,只有换行 / select 'OK' from dual; select 'OK' from dzual; --dual数据库经常使用于测试目的 select 'OK' from dual; spool off; --这个也必须,否则,脚本执行完成以后,会hang在sqlplus命令行中,不退出 exit;
查看存储过程的几个SQL,注意有的显示一行一行的,有的显示名字,有的显示内容:数据库
select name from user_source where type='PROCEDURE'; select text from all_source where name = 'pro_name'; select * from user_procedures;
最后一个小技巧,为何在的脚本里,会出现一个/右斜杠呢?????oracle
通常在end;(注意有分号)后加反斜杠/,表明是要执行某个存储过程,若是没有反斜杠,则表明是普通换行。这种状况通常用于oracle中的命令窗口。
https://zhidao.baidu.com/question/560015241204373364.html测试