|
藍森林 http://www.lslnet.com 2006年6月26日 11:18
請教一個shell與Oracle的SqlPlus互動的問題
我想在shell腳本中向sqlplus傳人參數,同時要將sqlplus的運行結果傳回shell。即想達到下面的效果:
[code]
#!/usr/bin/ksh
ORACLE_CONN=test/test@testdb
USER_ID="testuser"
USER_COUNT=0
sqlplus $ORACLE_CONN >> $LOGFILE <<EOF
-- 類似於 select count(*) into $USER_COUNT from employee where user_id = $USER_ID
exit;
EOF
echo $USER_ID
echo $USER_COUNT
[/code]
請問應該如何修改上面的代碼才能使它運行正常?多謝! |
請教一個shell與Oracle的SqlPlus互動的問題
上面的腳本沒有多大問題,但是請首先設定好oracle用戶的環境,不然腳本找不到sqlplus命令。 |
請教一個shell與Oracle的SqlPlus互動的問題
好像沒有那麼簡單。這是運行結果:
[code]
[test220]:~>more mytest.sh
#!/usr/bin/ksh
ORACLE_CONN=test/test@testdb
USER_ID=10
USER_COUNT=0
sqlplus $ORACLE_CONN <<EOF
select count(*) into $USER_COUNT from employee where user_id = $USER_ID ;
exit;
EOF
echo $USER_ID
echo $USER_COUNT
[test220]:~>mytest.sh
SQL*Plus: Release 9.2.0.1.0 - Production on Thu Aug 11 12:50:36 2005
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production
SQL> select count(*) into 0 from employee where user_id = 10
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL> Disconnected from Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production
[test220]:~>
[/code] |
請教一個shell與Oracle的SqlPlus互動的問題
這個錯誤已經很明顯了~~
SQL> select count(*) into 0 from employee where user_id = 10
*
ERROR at line 1:
ORA-00942: table or view does not exist
你再仔細看看 |
請教一個shell與Oracle的SqlPlus互動的問題
不好意思,請看下面:
[code]
[test220]:~>more test2.sh
#!/usr/bin/ksh
ORACLE_CONN=test/test@testdb
USER_ID=10
USER_COUNT=0
sqlplus $ORACLE_CONN <<EOF
select count(*) into $USER_COUNT from employee where user_id = $USER_ID ;
exit;
EOF
echo $USER_ID
echo $USER_COUNT
[test220]:~>mytest2.sh
bash: mytest2.sh: command not found
[test220]:~>mytest2.sh
bash: mytest2.sh: command not found
[test220]:~>test2.sh
SQL*Plus: Release 9.2.0.1.0 - Production on Thu Aug 11 14:23:30 2005
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production
SQL> select count(*) into 0 from employee where user_id = 10
*
ERROR at line 1:
ORA-00905: missing keyword
SQL> Disconnected from Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production
[/code] |
請教一個shell與Oracle的SqlPlus互動的問題
不好意思,由於顯示的原因,那個*應該指向哪個into的。 |
這個問題解決了嗎
我正好碰到同樣的問題,有人指點下嗎 |
select count(*) into 0 from employee where user_id = 10
這句什麼意思? |
可以先定義一個變量,然後打印出來
sqlplus ${DB_USERNAME}/${DB_USERPASS} <<END |grep ' *COL'|tail -1|read _sql_result
variable spret number;
execute sp_test_task(:spret);
select 'COL',:spret from dual;
END |
select into 是用於procedure中的,在普通的select語句中是不可取的。一般你可以生成一個文本,通過讀文本來獲得該變量。
一般我都這麼操作。 |
| |