数据库 发布日期:2024/12/27 浏览次数:1
这篇文章介绍一下如何对sqlplus执行的sql语句结果进行判断。
环境准备
使用Oracle的精简版创建docker方式的demo环境,详细可参看:
https://www.jb51.net/article/153533.htm
常见问题
在sqlplus中执行sql语句,如果直接使用命令行的方式调用时会碰到两个问题:
解决方式
在脚本调用里,解决方式如下
执行结果判断示例
这里使用命令行的方式进行验证,直接拷贝到脚本中即可以使用脚本的方式与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:~$总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对的支持。如果你想了解更多相关内容请查看下面相关链接