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?
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