简体   繁体   English

如何从sqlplus获取SQL查询output到bash脚本

[英]how to get SQL query output from sqlplus to bash script

how to execute sql query or script using sqlplus as the middle man and insert output to bash variable?如何使用 sqlplus 作为中间人执行 sql 查询或脚本并将 output 插入 bash 变量?

nothing worked for me of the (at least) 3 good looking stack-overflow and other websites tutorials so I'm posting what worked for me, for the of chance that it will be useful to some one else. (至少)3 个好看的堆栈溢出和其他网站教程对我没有任何帮助,所以我发布了对我有用的内容,因为它可能对其他人有用。

the code:编码:

#!/bin/bash
export ORACLE_SID=<DB_SID>
VAL=""
VAL=`sqlplus -s / as sysdba << EOF
whenever sqlerror exit sql.sqlcode;
set echo off
set heading off
@<sql_script_path>
exit;
EOF`
echo $VAL 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从shell / shell脚本获取sqlplus命令的输出状态? - How to get output status of sqlplus command from shell/shell script? 如何隐藏或抑制sqlplus中日志文件(假脱机文件)的sql查询输出 - How to hide or supresss sql query output from the log file (spool file ) in sqlplus 从 SQLPlus 运行 SQL 脚本失败时如何查看错误? - How to see the error when running an SQL script from SQLPlus fails? 如何将 sqlplus 参数从 shell 脚本传递到 sql 文件 - How to Pass a sqlplus parameter from shell script to sql file 无法从SQL Server查询管理器执行SQL脚本,如@ {file.sql} oracle sqlplus语法? - No way to execute SQL script from SQL Server Query Manager like @{file.sql} oracle sqlplus syntax? 如何从 bash 中的 SQL 查询中缩小 output - How I can shrink output from SQL Query in bash 如何从SQL查询中获取整数输出 - How to get an integer output from an SQL query 如何从SQL查询中获得所需的输出 - How to get desired output from this query in sql 如何从Java中的Oracle SQL select中获取原始脚本输出而不是查询结果 - How do I get the raw script output instead of the query result from an Oracle SQL select in Java 如何将bash变量传递给sqlplus,然后将该输出传递给另一个变量 - How to pass a bash variable to sqlplus and then pass that output to another variable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM