谢谢大家,用*.sql然后在ORCLE中执行当然,可以,我是想实验一下用SHELL
转义后还有一点问题,大家帮我看看,谢谢!
看我执行,还有错
-bash-3.00$ ls
spid.sh spid.sql
-bash-3.00$ sh spid.sh
SQL*Plus: Release 9.2.0.7.0 - Production on Mon Nov 5 06:54:55 2007
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
SQL> Connected.
SQL> SQL> SQL> SQL> SQL> 2 3 4 ( select addr from v$process where spid in())
*
ERROR at line 4:
ORA-00936: missing expression
SQL> SQL> 2 3 4 5 6 paddr in (select addr from v$process where spid=
)
*
ERROR at line 4:
ORA-00936: missing expression
SQL> Disconnected from Oracle9i Enterprise Edition Release 9.2.0.7.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP and Oracle Data Mining options
JServer Release 9.2.0.7.0 - Production
-bash-3.00$
-bash-3.00$ ls
spid.sh spid.sql
脚本代码如下
-bash-3.00$ cat spid.sh
#!/bin/sh
sqlplus /nolog <
connect / as sysdba
col machine format a30
col program format a40
set lines 200
set pages 1000
select sid,serial# ,username,osuser,machine,program,process,to_char(logon_time,
'yyyy/mm/dd hh24:mi:ss')
from v$session where paddr in
( select addr from v\$process where spid in($1));
select sql_text from v\$sqltext_with_newlines
where hash_value in
(select SQL_HASH_VALUE from v\$session where
paddr in (select addr from v\$process where spid=$1)
)
order by piece;
exit;
EOF
-bash-3.00$