How can i export entries from table into a variable and parse them?

Hi,
I need to export some entries from a table, from a specific column and then redirect them into a file.
I used sql plus, in order to fetch the entries and i put them in one variable.
When i am running the script it stuck at a point and does not move further.

I did something like:

$OUTPUT=`sqlplus -s $USER/$PASS@$INST << END
SELECT col1
FROM table
WHERE col2='A';
EXIT;
END`

for element in $OUTPUT
do
        echo $OUTPUT
done

variables $USER/$PASS@$INST, contain correctly the db details, as per what i see after doing echo

Could someone advice?
Thank you

END needs to be on a line by itself. That means no indenting and not putting a ` on the end. Just END, at the beginning of the line, all by itself.

Put ` on the following line.

I still have the same problem :frowning:

Please show us WHAT EXACTLY you did; setting the -x (xtrace) option will show in detail what the shell executes.

Just my thoughts. you need to remove "$" sign from the variable name"OUTPUT". and for best practice you need to enclose your variables with curly brackets "{}" .


OUTPUT=$(sqlplus -s ${USER}/${PASS}@${INST} << END
SELECT col1
FROM table
WHERE col2='A';
EXIT;
END)

for element in $OUTPUT
do
        echo $OUTPUT
done

1 Like