sqlplus设置提示符
作为DBA,需要管理好多数据库,经常会有一台服务器安装多个oracle实例的情况,为避免误操作实例,我们需要在执行sqkplus前,先通过$ echo $ORACLE_SID或 SQL>select name from v$database查看当前实例,这样难免有些麻烦。
那么,是否可以实现在sqlplus中显示当前实例名呢?
答案是肯定的,下面我就来说说如何设置sqlplus提示符。
1.在oracle用户下打开 $ORACLE_HOME/sqlplus/admin目录
# su - oracle
$ cd $ORACLE_HOME
[oracle@ocpstudy db_1]$ ls
addnode ctx dmu inventory mgw oraInst.loc precomp root.sh.old.1 sqlj wwg
apex cv drdaas javavm network ord QOpatch root.sh.old.2 sqlpatch xdk
assistants data dv jdbc nls ords R root.sh.old.3 sqlplus
bin dbjava env.ora jdk odbc oss racg runInstaller srvm
cfgtoollogs dbs has jlib olap oui rdbms schagent.conf suptools
clone deinstall hs ldap OPatch owm relnotes sdk ucp
crs demo install lib opmn perl root.sh slax usm
css diagnostics instantclient md oracore plsql root.sh.old sqldeveloper utl
[oracle@ocpstudy db_1]$ cd sqlplus/admin
[oracle@ocpstudy db_1]$ ls
glogin.sql help libsqlplus.def plustrce.sql pupbld.sql pupdel.sql
2.修改 glogin.sql 文件
[oracle@ocpstudy db_1]$vim glogin.sql
在末尾添加如下内容:
set termout off
column propmt_c new_value propmt_c
SELECT SYS_CONTEXT ('USERENV', 'CON_NAME') as propmt_c FROM DUAL;
set sqlprompt "_user'@'_connect_identifier(&propmt_c)> "
3.再次打开sqlplus可以看到提示符
[oracle@ocpstudy admin]$ sqlplus / as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on Sat Mar 16 21:08:30 2024
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
SYS@orcl(CDB$ROOT)>