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. easyui datagrid分页要点总结

    easyui的datagird插件比较好用,也很方便.网上也有很多热的网友贴出了使用代码,但是很少有网友指出在使用过程应该注意的地方,让我实在搞不清分页应该怎么使用.我就说下使用分页功能中要注意的一个 ...

  2. 【C语言】01-C语言概述

      说明:这个C语言专题,是学习iOS开发的前奏.也为了让有面向对象语言开发经验的程序员,能够快速上手C语言.如果你还没有编程经验,或者对C语言.iOS开发不感兴趣,请忽略 为什么iOS开发要先学C语 ...

  3. jsp七大动作指令

    jsp 七大动作指令 1) jsp:include 指令 用于在请求处理阶段包含来自一个Servlet或jsp页面的响应.和编译指令中的include不同,include只能用于包含静态页面,而jsp ...

  4. Objective-C中属性及其特质@property、attribute

    属性: 属性@property和属性attribute不同,@property在OC里有自己的一套专对实例变量的处理机制.attribute我们可以特指属性所具有或遵循的特质. 使用属性,编译器就会自 ...

  5. 【Objective-C】Windows下Objective-C开发环境配置

    [Objective-C]Windows下Objective-C开发环境配置 ftp://ftpmain.gnustep.org/pub/gnustep/binaries/windows/   最近打 ...

  6. linux下创建和删除软、硬链接

    linux下创建和删除软.硬链接 在Linux系统中,内核为每一个新创建的文件分配一个Inode(索引结点),每个文件都有一个惟一的inode号.文件属性保存在索引结点里,在访问文件时,索引结点被复制 ...

  7. Rails--default_scope

    Example: default_scope where("agents.deleted = ?", false)

  8. Medusa: Gauges for JavaFX

    Medusa: Gauges for JavaFX https://community.oracle.com/docs/DOC-992746

  9. Python创建list和按照索引访问list

    Python创建list Python内置的一种数据类型是列表:list.list是一种有序的集合,可以随时添加和删除其中的元素.比如,列出班里所有同学的名字,就可以用一个list表示:>> ...

  10. Liunx 下使用cmake

    参考 http://blog.chinaunix.net/uid-28458801-id-3501768.html http://www.ibm.com/developerworks/cn/linux ...