万梅资源网 Design By www.ubjie.com

这篇文章介绍一下如何对sqlplus执行的sql语句结果进行判断。

环境准备

使用Oracle的精简版创建docker方式的demo环境,详细可参看:

 https://www.jb51.net/article/153533.htm

常见问题

在sqlplus中执行sql语句,如果直接使用命令行的方式调用时会碰到两个问题:

  • 问题1: 需要进行交互性的输入
  • 问题2:结果的判断不能通过返回值来确认

解决方式

在脚本调用里,解决方式如下

  • 问题1可以通过前文提到的Here Document来解决。
  • 问题2,则可以通过对输出的判断来进行,因为Oracle的错误代码基本以ORA-打头,所以根据输出中是否包含ORA-,基本可确认是否存在错误。

执行结果判断示例

这里使用命令行的方式进行验证,直接拷贝到脚本中即可以使用脚本的方式与sqlplus进行集成。

oracle@e871d42341c0:~$ sqlplus system/liumiao123@XE <<EOF
> desc student
> delete from student;
> select * from student;
> insert into student values (1001, 'liumiaocn');
> insert into student values (1001, 'liumiao');
> insert into student values (1003, 'michael');
> commit;
> select * from student;
> EOF
SQL*Plus: Release 11.2.0.2.0 Production on Mon Oct 22 05:18:51 2018
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
SQL> Name  Null"htmlcode">
oracle@e871d42341c0:~$ sqlplus system/abcd1234@XE <<EOF 2>output.error 1>output.info
> desc student
> delete from student;
> select * from student;
> insert into student values (1001, 'liumiaocn');
> insert into student values (1001, 'liumiao');
> insert into student values (1003, 'michael');
> commit;
> select * from student;
> EOF
oracle@e871d42341c0:~$ 
oracle@e871d42341c0:~$ cat output.error
oracle@e871d42341c0:~$ 
oracle@e871d42341c0:~$ cat output.info
SQL*Plus: Release 11.2.0.2.0 Production on Mon Oct 22 05:24:44 2018
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
SQL> Name  Null"htmlcode">
oracle@e871d42341c0:~$ sqlplus system/abcd1234@XE <<EOF >output.info 2>&1
> desc student
> delete from student;
> select * from student;
> insert into student values (1001, 'liumiaocn');
> insert into student values (1001, 'liumiao');
> insert into student values (1003, 'michael');
> commit;
> select * from student;
> EOF
oracle@e871d42341c0:~$ 
oracle@e871d42341c0:~$ cat output.info
SQL*Plus: Release 11.2.0.2.0 Production on Mon Oct 22 05:29:31 2018
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
SQL> Name  Null"external nofollow" href="mailto:oracle@e871d42341c0:~$">oracle@e871d42341c0:~$ grep ORA- output.info 
ORA-00001: unique constraint (SYSTEM.SYS_C007024) violated
oracle@e871d42341c0:~$ echo $"external nofollow" href="mailto:oracle@e871d42341c0:~$">oracle@e871d42341c0:~$

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对的支持。如果你想了解更多相关内容请查看下面相关链接

万梅资源网 Design By www.ubjie.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
万梅资源网 Design By www.ubjie.com

RTX 5090要首发 性能要翻倍!三星展示GDDR7显存

三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。

首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。

据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。