Oracle 用 sqlprompt 修改 sqlplus 提示符

当管理的数据库比较多的时候,在sqlplus里切换就是一件麻烦的事。 要非常小心,以防出错。 可以修改sqlplus 的提示符:SQL> ,把这个改成我们用户和实例名,这样就不容易出错。

先看一下Oracle 自定义的参数:

SQL> define

DEFINE _DATE = "11-MAY-11" (CHAR)

DEFINE _CONNECT_IDENTIFIER = "dave1" (CHAR)

DEFINE _USER = "SYS" (CHAR)

DEFINE _PRIVILEGE = "AS SYSDBA" (CHAR)

DEFINE _SQLPLUS_RELEASE = "1002000100" (CHAR)

DEFINE _EDITOR = "ed" (CHAR)

DEFINE _O_VERSION = "Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production

With the Partitioning, Real Application Clusters, OLAP and Data Mining options" (CHAR)

DEFINE _O_RELEASE = "1002000100" (CHAR)

我们可以使用这些定义的参数来设定相关信息,也可以使sql 来拼接显示的信息。 如:

SQL> set sqlprompt "_USER@ _CONNECT_IDENTIFIER >"

SYS@ dave1 >

但是这个方式在sqlplus 关闭之后就没有了。 要想永久的保存,就需要修改配置文件glogin.sqlsqlplus 在启动时,会读取该文件。 该文件位置:

$ORACLE_HOME/sqlplus/admin/glogin.sql

方法一:

$ORACLE_HOME/sqlplus/admin/glogin.sql 文件里添加如下参数:

set sqlprompt "_USER@ _CONNECT_IDENTIFIER >"

然后打开sqlplus

[oracle@rac1 admin]$ sqlplus / as sysdba;

SQL*Plus: Release 10.2.0.1.0 - Production on Wed May 11 18:46:50 2011

Copyright (c) 1982, 2005, Oracle. All rights reserved.

Connected to:

Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production

With the Partitioning, Real Application Clusters, OLAP and Data Mining options

SYS@ dave1>

方法二: 使用sql 语句拼接

$ORACLE_HOME/sqlplus/admin/glogin.sql 文件里添加如下参数:

set time on

set termout off -- 如果不加这句,每次都会显示下面查询的select 结果集
column propmt_q new_value propmt_q
select upper(user)||'@'|| instance_name||'('||host_name||')' as propmt_q from v$instance;
set sqlprompt '&propmt_q> '

在打开sqlplus,效果如下:

[oracle@rac1 admin]$ sqlplus / as sysdba;

SQL*Plus: Release 10.2.0.1.0 - Production on Wed May 11 18:50:27 2011

Copyright (c) 1982, 2005, Oracle. All rights reserved.

Connected to:

Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production

With the Partitioning, Real Application Clusters, OLAP and Data Mining options

18:50:27 SYS@dave1(rac1)>select sysdate from dual;

SYSDATE

---------

11-MAY-11

18:51:27 SYS@dave1(rac1)>

把时间去掉:

set termout off -- 如果不加这句,每次都会显示下面查询的select 结果集

column propmt_q new_value propmt_q
select upper(user)||'@'|| instance_name||'('||host_name||')' as propmt_q from v$instance;
set sqlprompt '&propmt_q> '

[oracle@rac1 admin]$ sqlplus / as sysdba;

SQL*Plus: Release 10.2.0.1.0 - Production on Wed May 11 18:55:06 2011

Copyright (c) 1982, 2005, Oracle. All rights reserved.

Connected to:

Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production

With the Partitioning, Real Application Clusters, OLAP and Data Mining options

SYS@dave1(rac1)>

整理自网络

-------------------------------------------------------------------------------------------------------

Blog http://blog.csdn.net/tianlesoftware

Email: [email protected]

DBA1 群:62697716(); DBA2 群:62697977() DBA3 群:62697850()

DBA 超级群:63306533(); DBA4 群: 83829929 DBA5群: 142216823

聊天 群:40132017 聊天2群:69087192

--加群需要在备注说明Oracle表空间和数据文件的关系,否则拒绝申请

你可能感兴趣的:(oracle,sql,C++,c,Gmail)