SQLPlus directive "WHENEVER SQLERROR EXIT 1" will return a specified code when any SQL error throwed when run a sql file.

Then we can catch the return code from the main bat file (where we call the sqlplus) to test it and then jump to a  correspondence code.

Below is a example, gpdemo.sql is a normal sql file, it will be execute by sqlplus called from main.bat.

The main.bat will test the return code to know whether any sql error occurred when execute the gpdemo.sql.

gpdemo.sql

WHENEVER SQLERROR EXIT 1;

DECLARE
V_USER_EXISTED INT;
BEGIN
SELECT COUNT(1) INTO V_USER_EXISTED FROM DBA_USERS WHERE USERNAME='GPDEMO'; IF V_USER_EXISTED >= 1 THEN
EXECUTE IMMEDIATE 'DROP USER GPDEMO CASCADE';
END IF; EXECUTE IMMEDIATE 'CREATE USER GPDEMO IDENTIFIED BY SUNGARD01'; EXECUTE IMMEDIATE 'GRANT CREATE TABLE TO GPDEMO'; EXECUTE IMMEDIATE 'GRANT CREATE VIEW TO GPDEMO'; EXECUTE IMMEDIATE 'GRANT CREATE PROCEDURE TO GPDEMO'; EXECUTE IMMEDIATE 'GRANT CREATE SEQUENCE TO GPDEMO'; EXECUTE IMMEDIATE 'GRANT CREATE SYNONYM TO GPDEMO'; EXECUTE IMMEDIATE 'GRANT CREATE SESSION TO GPDEMO'; EXECUTE IMMEDIATE 'GRANT GETPAID_ROLE TO GPDEMO'; EXECUTE IMMEDIATE 'ALTER USER GPDEMO DEFAULT TABLESPACE GP_DATA'; EXECUTE IMMEDIATE 'ALTER USER GPDEMO TEMPORARY TABLESPACE TEMP'; EXECUTE IMMEDIATE 'ALTER USER GPDEMO QUOTA UNLIMITED ON GP_DATA'; EXECUTE IMMEDIATE 'ALTER USER GPDEMO QUOTA UNLIMITED ON GP_INDX';
END;
/ EXIT 0

main.bat

:: Clear the ERRORLEVEL environment if it had defined.
set ERRORLEVEL =
:: Drop and recreate GPDEMO
sqlplus system/manager@GPODTE @gpdemo.sql >> DROPUSER.log
:: RELOAD dump file to GPDEMO
if ERRORLEVEL 1 (
ECHO "Failed to Drop user, check the DROPUSER.log for detail error message"
) else (
ECHO "Drop User Successfully, will continute to do import"
imp system/manager@GPODTE fromuser=gpcomp1 touser=GPDEMO file=gpdemo.dmp log=gpdemo.log statistics=none
)

SQLPlus Error handle的更多相关文章

  1. sqlplus: error while loading shared libraries: /u01/app/lib/libclntsh.so.11.1

    成功安装了Oracle 11g后,使用sqlplus登录数据库时遇到下面错误: [oracle@DB-Server ~]$ sqlplus / as sysdba   sqlplus: error w ...

  2. sqlplus: error while loading shared libraries: libsqlplus.so: cannot open shared object file

    sqlplus: error while loading shared libraries: libsqlplus.so: cannot open shared object file 1. 权限问题 ...

  3. ORACLE11.2.0 SQLPLUS 报 error while loading shared libraries

    相应的环境平台: OS: Linux TEST11G 2.6.18-8.el5 #1 SMP Fri Jan 26 14:15:21 EST 2007 i686 i686 i386 GNU/Linux ...

  4. Android Volley gives me 400 error

    本文来自:http://stackoverflow.com/questions/21739276/android-volley-gives-me-400-error 本人是根据文中的其中一方法: I ...

  5. Cloning EBS from Linux 5 to Linux 6 Fails: "Error While Loading Shared Libraries: libclntsh.so.10.1

    SYMPTOMS    During clone Oracle Applications R12 from Linux 5 to Linux 6 the following error occurs ...

  6. sqlplus 一次奇葩问题 HTTP proxy setting has incorrect value

    y@y:~$ sqlplus Error 46 initializing SQL*PlusHTTP proxy setting has incorrect valueSP2-1502: The HTT ...

  7. 20140603 对error.c 用于分析源代码

    20140603 对error.c 用于分析源代码 继续看error.c该功能 买家现在将自己的代码和数据汇编例如,下面的:   1.#include <stdio.h>   2 #inc ...

  8. 【Oracle】-【sqlplus / as sysdba登录报错问题】-新用户使用sqlplus / as sysdba登录报错

    刚才打开一个别人的测试库,用root登陆了的,sqlplus / as sysdba竟然报错,奇怪,于是在自己的VM中模拟该过程. 新建了一个test用户: [test@liu bin]# ./sql ...

  9. 不一样的go语言-error

    前言   go语言的error处理方式,在目前流行的编程语言中属于刺头.似乎天生就是用来有别于他人标记.TIOBE排行榜全十除了C语言,无一例外是try catch的阵营.而排在go之前的语言除了C与 ...

随机推荐

  1. JQuery图形插件,Highcharts平滑线条处理方法

    第一种:静态数据 $('#THChartDiv').highcharts({ chart: { type: 'spline' }, title: { text:过程线' }, xAxis: { tit ...

  2. jstl fn标签

    JSTL使用表达式来简化页面的代码,这对一些标准的方法,例如bean的getter/setter方法,请 求参数或者context以及session中的数据的访问非常方便,但是我们在实际应用中经常需要 ...

  3. Java 读写图像

    Java中进行图像I/O(即读图片和写图片,不涉及到复杂图像处理)有三个方法:1. Java Image I/O API,支持常见图片,从Java 2 version 1.4.0开始就内置了.主页:h ...

  4. 使用Objective-C的文档生成工具:appledoc

    使用Objective-C的文档生成工具:appledoc 前言 做项目的人多了,就需要文档了.今天开始尝试写一些项目文档.但是就源代码来说,文档最好和源码在一起,这样更新起来更加方便和顺手.象 Ja ...

  5. Autoencoder

    AutoencoderFrom Wikipedia An autoencoder, autoassociator or Diabolo network[1]:19 is an artificial n ...

  6. php100 的下拉分页效果

    <?php function _PAGEFT($totle, $displaypg = 20, $url = '') { global $page, $firstcount, $pagenav, ...

  7. [排错] PATH_MISSING

    症状: 更换了磁带机部件,导致Robots选项卡中的TLD(2) Robotic Path显示为PATH_MISSING. 解决方法: 概括起来就是: 删除TLD(2),重新创建Robot记录,然后重 ...

  8. css 细节收集

    细节1……………………………………………………………………………… 一.当文字与图片在一行,需要将文字与图片底对齐,需要这样写: <li>记住密码<img src="&qu ...

  9. ORA-01791: 不是 SELECTed 表达式

    Oracle 9i数据库,执行下面语句出现错误“ORA-01791: 不是 SELECTed 表达式”:select distinct t.name from auth_employee t orde ...

  10. HTTP 笔记与总结(8)HTTP 与内容压缩

    以环球网的一篇新闻为例,抓包图: (Powered-By-ChinaCache:HIT from 060120b3g7.16 表示当前页面不是来自环球网的主服务器,而是来自中国的缓存服务器节点,HIT ...