关于sqlplus的show parameter问题

这里先描述几个视图:v$parameter 、 v$system_parameter、v$spparameter

v$parameter : displays information about the initialization parameters that are currently in effect for the session. A new session inherits parameter values from the instance-wide values displayed by the V$SYSTEM_PARAMETER view. 

v$system_parameter : displays information about the initialization parameters that are currently in effect for the instance. A new session inherits parameter values from the instance-wide values.

v$spparameter : displays information about the contents of the server parameter file. If a server parameter file was not used to start the instance, then each row of the view will contain FALSE in the ISSPECIFIED column.

说白了就是:v$parameter描述会话级别的参数, v$system_parameter描述实例级别的参数, v$spparameter描述spfile文件的参数。新建的会话继承v$system_parameter里描述的参数。

问题:当以scott用户登录到数据库之后,想查看当前会话某个参数的值,可是报错了

C:\Users\zlf>sqlplus /nolog

SQL*Plus: Release 11.2.0.1.0 Production on 星期日 6月 15 20:10:21 2014

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

SQL> conn scott/tiger@demodb
已连接。
SQL> show user
USER 为 "SCOTT"
SQL> set linesize 200
SQL> select * from emp;

     EMPNO ENAME      JOB              MGR HIREDATE              SAL       COMM     DEPTNO
---------- ---------- --------- ---------- -------------- ---------- ---------- ----------
      7369 SMITH      CLERK           7902 17-12月-80            800                    20
      7499 ALLEN      SALESMAN        7698 20-2月 -81           1600        300         30
      7521 WARD       SALESMAN        7698 22-2月 -81           1250        500         30
      7566 JONES      MANAGER         7839 02-4月 -81           2975                    20
      7654 MARTIN     SALESMAN        7698 28-9月 -81           1250       1400         30
      7698 BLAKE      MANAGER         7839 01-5月 -81           2850                    30
      7782 CLARK      MANAGER         7839 09-6月 -81           2450                    10
      7839 KING       PRESIDENT            17-11月-81           5000                    10
      7844 TURNER     SALESMAN        7698 08-9月 -81           1500          0         30
      7900 JAMES      CLERK           7698 03-12月-81            950                    30
      7902 FORD       ANALYST         7566 03-12月-81           3000                    20

     EMPNO ENAME      JOB              MGR HIREDATE              SAL       COMM     DEPTNO
---------- ---------- --------- ---------- -------------- ---------- ---------- ----------
      7934 MILLER     CLERK           7782 23-1月 -82           1300                    10

已选择12行。

SQL> show parameter nls_date_format
ORA-00942: table or view does not exist  -- 提示表或视图不存在

解释:当在sqlplus下通过show parameter parameter_name查询某个参数值时,后台实际上是查询v$parameter来返回会话参数。那为什么scott用户无法查看当前自己的会话参数呢?troubleshoot

1. 先要看看v$parameter是什么类型的对象

[oracle@redhat4 ~]$ sqlplus /nolog

SQL*Plus: Release 10.2.0.1.0 - Production on 星期日 6月 15 20:23:30 2014

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

SQL> conn / as sysdba
Connected.
SQL> col object_name format a30
SQL> select owner,object_name,object_type from dba_objects where object_name='V$PARAMETER';

OWNER                          OBJECT_NAME                    OBJECT_TYPE
------------------------------ ------------------------------ -------------------
PUBLIC                         V$PARAMETER                    SYNONYM

SQL>

通过查询结果可以知道:v$parameter其实是一个public synonym, 既然是公共同义词,那所有用户都可以访问,为什么scott用户访问报错呢?猜测:v$parameter这个公共同义词指向的对象并没有把查询权限赋予public用户,导致最后查询还是失败。

2.  查看 同义词v$parameter指向哪个对象

SQL> conn / as sysoper
Connected.
SQL> show user
USER is "PUBLIC"
SQL> select SYNONYM_NAME,TABLE_OWNER,TABLE_NAME from user_synonyms where SYNONYM_NAME='V$PARAMETER';

SYNONYM_NAME                   TABLE_OWNER                    TABLE_NAME
------------------------------ ------------------------------ ------------------------------
V$PARAMETER                    SYS                            V_$PARAMETER

发现:同义词v$parameter其实指向sys.V_$PARAMETER

3. sys.V_$PARAMETER又是什么类型的对象

SQL> conn / as sysdba
Connected.
SQL> show user
USER is "SYS"
SQL> select object_name,object_type from user_objects where object_name='V_$PARAMETER';

OBJECT_NAME                    OBJECT_TYPE
------------------------------ -------------------
V_$PARAMETER                   VIEW

发现:sys.V_$PARAMETER其实是一个视图, 至于这个视图又是由哪几个表构成,这里就不介绍了。也就是说:我们通过show parameter查询的参数值其实是来自于

sys.V_$PARAMETER,可现在报错了,提示表或视图不存在。那我们再看看sys用户有没有将sys.V_$PARAMETER的查询权限赋予public用户

4. 查看sys用户有没有将sys.V_$PARAMETER的查询权限赋予public用户

QL> conn / as sysoper
Connected.
SQL> show user
USER is "PUBLIC"
SQL> select * from user_tab_privs where owner='SYS' and TABLE_NAME='V_$PARAMETER';

no rows selected  --没有

5. 找到问题的原因了,只要将sys.V_$PARAMETER的查询权限赋予public用户即可,当然也可以单独赋予单独的某一个用户

SQL> conn / as sysdba
Connected.
SQL> show user
USER is "SYS"
SQL> grant select on V_$PARAMETER to public;

Grant succeeded.

SQL> conn / as sysoper
Connected.
SQL> show user
USER is "PUBLIC"
SQL> select * from user_tab_privs where owner='SYS' and TABLE_NAME='V_$PARAMETER';

GRANTEE                    OWNER                          TABLE_NAME                     GRANTOR  PRIVILEGE                                GRA   HIE
PUBLIC                         SYS                                V_$PARAMETER                   SYS            SELECT                                   NO      NO
现在public用户拥有了对sys.V_$PARAMETER的查询权限,那数据库的所有用户自然也就拥有了。

6. 校验show parameter 是否可以

SQL> conn scott/tiger@demodb
已连接。
SQL> show user
USER 为 "SCOTT"
SQL> show parameter service_names

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
service_names                        string      demodb
SQL>

OK,可以了。

 

 

 

 

 
  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

历史五千年

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值