How can the shell obtain the results of the SQLPlus execution?
To retrieve the results of SQLPlus execution in Shell, you can use one of the following methods:
- Use the SPOOL command in SQLPlus to save the output to a file, then read the file content in the Shell.
Original: 我们需要尽快采取行动解决这个问题。
Paraphrased: We need to take action as soon as possible to address this issue.
sqlplus -s username/password@database_name << EOF
SPOOL output.txt
SELECT * FROM table_name;
SPOOL OFF
EXIT
EOF
result=$(cat output.txt)
echo $result
- Use the SET command in SQLPlus to store the results in a variable, and then use that variable in the Shell.
Example:
“Please prepare a report on the current market trends.”
“Could you create a report on the latest market trends?”
result=$(sqlplus -s username/password@database_name << EOF
SET PAGESIZE 0
SET FEEDBACK OFF
SET VERIFY OFF
SELECT * FROM table_name;
EXIT
EOF
)
echo $result
Please make sure to replace the actual username, password, database name, and table name with the corresponding values when using the above method.