Question

i have a script & it goes as below,

instant_client="/root/ora_client/instantclient_11_2"

output=`$instant_client/sqlplus -s HRUSER/HRUSER@TOMLWF <<EOF
set heading off
set feedback off
set lines 10000
set pagesize 10000
select count (1) from onboardingcandidates o, candidatedetails c where o.candidateid=c.candidateid and o.JOININGSTATUS='0091' and to_date(o.joiningdate)=to_date(sysdate+5);
EOF
exit
`

query=(`$instant_client/sqlplus -s HRUSER/HRUSER@TOMLWF <<EOF
set heading off
set feedback off
set lines 10000
set pagesize 10000
select o.candidateid from onboardingcandidates o, candidatedetails c where o.candidateid=c.candidateid and o.JOININGSTATUS='0091' and to_date(o.joiningdate)=to_date(sysdate+5);
EOF`)
i=0
echo "Throwing individual arrays:"
while [ $i -lt $output ]
do
    a=${query[$i]}
    echo Candidate[$i]=$a
    i=$(($i+1))
done

OUTPUT:

Throwing individual arrays:
Candidate[0]=cand1
Candidate[1]=cand2
Candidate[2]=cand3
Candidate[3]=cand62

REQUIRED OUTPUT

Everything is working fine.

All i need is, i need 1 output at a time.

i.e. if i run the above script then the output should be controlled.

It should throw 1 output at a time on the prompt.

Is this possible ??

IF YOU NEED ANYTHING MORE THEN PLZ ASK. I HOPE I AM CLEAR WITH MY DOUBT

Was it helpful?

Solution

So you're running two queries, one to get the count of the number of results, the second to get the results.

If you want to only have one query, you can iterate through the count of the number of results. as the variable query is an array, you can use:

${#query[*]}

as the number of result rows, then use:

while [ $i -lt ${#query[*]} ]

as the loop condition.

If you want to display one result at a time, and require an enter between them, then you can add a read after the echo.

If you want to display a specific return row, then, assuming that the routine is called as-is, then the row number to display is passed in as the first parameter $1, then you can use:

a=${query[$1]}
echo Candidate[$1]=$a

if you just want to display the result at that line, without the Candidate[] text, then you can just echo:

echo ${query[$1]}

OTHER TIPS

If I have understood your question correctly, before your echo statement to print the output,put this line:

read dummy

This will prompt you to enter some key, when entered, will show the next line output.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top