将 sql 数据存储在嵌套 if 的变量中
我必须使用嵌套的 if/then/else 语句来检查从 oracle db 获得的查询。 我是 UNIX 新手。通过在google上搜索,我了解了将sql数据存储到变量中的过程。但是当我必须使用嵌套的 if 语句时,我该怎么做?
我无法一次又一次连接到数据库以将数据存储到变量中。有人可以帮忙吗?
我在这里写的是代码。请原谅错误的语法。我来自 php 编码
LOGFILE = #enter path here
fetchdate = `sqlplus -s prmappo/prmappo@PRMDB << EOFSQL
select min(call_start_datetime) from error_repository;
exit;
EOFSQL`
if (( "${fetchdate:4:2}" == "02" ));
then
$query_1 = select * from error_repository_BKP partition(part_maxval);
if (($query_1 == NULL));
then
$query_2 = "alter table error_repository_BKP
exchange partition part_maxval
with table error_repository
without validation;" >> $LOGFILE
commit;
fi
$query_3 = "select * from error_repository;"
另外,请告诉我如何读取存储在变量中的 SQL 行数据?
i have to use nested if/then/else statements to check the queries obtained from oracle db.
i am new to unix. from searching on google, i understand the procedure for storing sql data into variables. but when i have to use nested if statements, how can i do that?
i cannot connect to the database again and again for storing data into variables. can someone please help?
what i am writing here is teh code. excuse the wrong syntax. i am coming from coding for php
LOGFILE = #enter path here
fetchdate = `sqlplus -s prmappo/prmappo@PRMDB << EOFSQL
select min(call_start_datetime) from error_repository;
exit;
EOFSQL`
if (( "${fetchdate:4:2}" == "02" ));
then
$query_1 = select * from error_repository_BKP partition(part_maxval);
if (($query_1 == NULL));
then
$query_2 = "alter table error_repository_BKP
exchange partition part_maxval
with table error_repository
without validation;" >> $LOGFILE
commit;
fi
$query_3 = "select * from error_repository;"
Also, please tell me how do I read the SQL row data stored in the variables?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想使用 sqlplus 编写脚本,最简单的方法是将数据以某种单独的格式存储到文件中,并解释该文件的输出。您可以从假脱机文件的字段中分配变量。
除非您正在操作操作系统对象,否则完全使用 pl/sql 进行编码可能会更明智。在这种情况下,您可以完全控制并且在分配任务时完全没有问题。如果您只操作 Oracle 对象,请尝试 pl/sql。这是一种功能强大的编程语言。这样做还可以防止大量额外的数据库连接。如果您使用 11g,您还可以使用远程作业代理来操作操作系统对象。
使用 sqldeveloper 编码和调试代码。从此处下载: Oracle SQL 开发人员
If you want to use sqlplus for scripting, easiest is to spool the data in some separated format to a file and interpret the output from that file. You can assign the variables from the fields of the spool file.
Unless you are manipulating OS objects, it might be smarter to code completely in pl/sql. In that case you have full control and have no problems with assignments at all. If you are only manipulating Oracle objects, try pl/sql. This is a powerful programming language. Doing so also prevents lots of extra database connections. If you use 11g, you can also manipulate OS objects by using the remote job agent.
Use sqldeveloper to code and debug your code.download from here: Oracle SQL Developer