Oracle:自定义SQL*Plus的命令提示符
除了Linux的命令提示符可以自定义之外,Oracle的SQL*Plus的命令提示符也是可以自定义的。
关于它的设定方法有两种:
一、通过SQL*Plus的自定义提示符变量设置
具体配置如下所示:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
[oracle@ora12c - allah:~]$ sqlplus / as sysdba SQL*Plus: Release 12.1.0.2.0 Production on Tue Oct 28 18:41:37 2014 Copyright (c) 1982, 2014, Oracle. All rights reserved. Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options SQL> select name from v$database; NAME --------- ALLAH SQL> show user USER is "SYS" SQL> set sqlprompt '&_USER.@&_CONNECT_IDENTIFIER. &_PRIVILEGE:&_DATE> ' SYS@allah AS SYSDBA:28-OCT-14> exit Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options [oracle@ora12c - allah:~]$ |
正如上面的LOG所示:set sqlprompt ‘&_USER.@&_CONNECT_IDENTIFIER. &_PRIVILEGE:&_DATE> ‘
为设置的命令。
关于自定义提示符的变量的详细列表条目:
_CONNECT_IDENTIFIER,连接标识符
_DATE,当前日期
_EDITOR,SQL Edit命令调用的编辑器
_O_VERSION,Oracle的版本
_O_RELEASE,Oracle的发行号
_PRIVILEGE,当前连接会话的权限等级
_SQPLUS_RELEASE,SQL*Plus的发行号
_USER,当前使用的用户
二、设置SQL*Plus登录时自动执行的命令脚本
1.定义脚本所在目录
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
[oracle@ora12c - allah:~]$ env | grep --color SQLPATH [oracle@ora12c - allah:~]$ ll total 72 -rw-r--r-- 1 oracle oinstall 8656 Oct 16 01:07 12c.rsp -rw-r--r-- 1 oracle oinstall 25232 Oct 16 00:30 db.rsp -rwxr-xr-x 1 oracle oinstall 25234 Oct 16 00:41 inst.rsp -rw-r--r-- 1 oracle oinstall 2259 Oct 27 22:08 space.sql [oracle@ora12c - allah:~]$ mkdir script [oracle@ora12c - allah:~]$ cd script/ [oracle@ora12c - allah:~/script]$ pwd /home/oracle/script [oracle@ora12c - allah:~/script]$ [oracle@ora12c - allah:~/script]$ export SQLPATH=/home/oracle/script [oracle@ora12c - allah:~/script]$ [oracle@ora12c - allah:~/script]$ env | grep SQLPATH SQLPATH=/home/oracle/script [oracle@ora12c - allah:~/script]$ |
2.编辑脚本文件:login.sql
1 2 3 4 5 6 |
[oracle@ora12c - allah:~/script]$ ll total 4 -rw-r--r-- 1 oracle oinstall 67 Oct 28 22:40 login.sql [oracle@ora12c - allah:~/script]$ cat login.sql set sqlprompt '&_USER.@&_CONNECT_IDENTIFIER. &_PRIVILEGE:&_DATE> ' [oracle@ora12c - allah:~/script]$ |
3.登入SQL*Plus,查看效果:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
[oracle@ora12c - allah:~/script]$ sqlplus / as sysdba SQL*Plus: Release 12.1.0.2.0 Production on Tue Oct 28 22:41:36 2014 Copyright (c) 1982, 2014, Oracle. All rights reserved. Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options SYS@allah AS SYSDBA:28-OCT-14> exit Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options [oracle@ora12c - allah:~/script]$ |
可以看到登录SQL*Plus后,提示符被自动更改了。
——————————————————
Finished。