2010-11-09 60 views
0

如何將從表中檢索到的列值存儲到shell腳本中的變量中。使用shell腳本從sql腳本中選擇列到本地變量

我有以下代碼:

#!/usr/bin/ksh 

echo "This script will try to connect to sql plus and displays the date" 
echo 

sqlplus user/password << EOF 
SELECT sysdate 
from dual; 
EOF 
exit; 

echo "End of SQL" 

我需要SYSDATE的值保存到一個局部變量和回聲它。我怎麼做?

回答

1

這對我有效。

#!/usr/bin/ksh 

clear 

echo "This will print the Date" 

VALUE=`sqlplus -silent apps/Z4vRD3me <<END 
set pagesize 0 feedback off verify off heading off echo off 
select sysdate from dual 
exit; 
END` 


# xx=$(echo 'select sysdate from dual' | sqlplus -silent apps/Z4vRD3me) 

echo $VALUE 

echo "End of SQL"