set term off
-- a lot of stuff
REM here is how I set my signature prompt in sqlplus to
REM username@database> I use the NEW_VALUE concept to format
REM a nice prompt string that defaults to IDLE (useful for those
REM of you that use sqlplus to start up their databases - the
REM prompt will default to idle> if your database isn't started)
define gname=idle
column global_name new_value gname
select lower(user) || '@' ||
substr(global_name, 1, decode(dot, 0, length(global_name), dot-1)) global_name
from (select global_name, instr(global_name, '.') dot
from global_name);
set sqlprompt '&gname> '
-- a lot of more stuff
set term on
#!/bin/bash
# set -x
#
# This script checks to see if a database is open
#
if [ $# -lt 1 ]; then
echo "Usage: Sid_name"
exit 1
fi
# Set the ORACLE_SID with the first parameter.
# I need to hardcode ${HOME}/scripts because it sets
# the BIN_DIR environment variable
. ${HOME}/scripts/bin/set_oracle_env.sh ${1}
# Log into the DB through SQLPLUS. You must be the oracle user.
export DBISOPEN=`sqlplus -s /nolog << EOF
CONN /as sysdba
SET TERM OFF
SET ECHO OFF
SET TRIM ON
SET FEEDBACK OFF
SET PAGESIZE 0
SET LINESIZE 130
SET TIMING OFF
SET TERM ON
select status from v\\$instance;
EOF`
if [ "${DBISOPEN}" == OPEN ]; then
echo "TRUE"
else
echo "FALSE"
fi
这是我在 login.sql 中使用的。Tom Kytes 的书专家一对一有这个脚本。实例关闭时没有 ORA-01034 的迹象。我的提示只显示
idle>
我写了这个 shell 脚本来查看数据库是否打开。您可能可以更改它以寻找其他东西。