我现在以scott启动了两个会话 SYS启动一个
查询V$SESSION结果如下
SQL> select paddr,user#,username,schema#,schemaname from v$session;PADDR                USER# USERNAME           SCHEMA# SCHEMANAME
--------------- ---------- --------------- ---------- ---------------
6DA4D1DC                54 SCOTT                   54 SCOTT
6DA50D3C                 0                          0 SYS
6DA4DDBC                 0                          0 SYS
6DA4EF8C                 0                          0 SYS
6DA4E99C                 0                          0 SYS
6DA4E3AC                 0                          0 SYS
6DA4FB6C                 0 SYS                      0 SYS
6DA4D7CC                 0                          0 SYS
6DA4C5FC                 0                          0 SYS
6DA4CBEC                 0                          0 SYS
6DA4F57C                54 SCOTT                   54 SCOTTPADDR                USER# USERNAME           SCHEMA# SCHEMANAME
--------------- ---------- --------------- ---------- ---------------
6DA4B42C                 0                          0 SYS
6DA4AE3C                 0                          0 SYS
6DA4A84C                 0                          0 SYS
6DA4A25C                 0                          0 SYS
6DA49C6C                 0                          0 SYS
6DA4967C                 0                          0 SYS
6DA4908C                 0                          0 SYS
6DA48A9C                 0                          0 SYS
6DA484AC                 0                          0 SYS
6DA47EBC                 0                          0 SYS
6DA478CC                 0                          0 SYS22 rows selected.SQL>
1
这里为什么要设置USER#和SCHEMA#,USERNAME和SCHEMANAME呢?内容是差不多一样的呀。
2
当然,还有一些不一样的地方,就是那些SCHEMANAME为SYS,但USERNAME为空的那些进程,都是些后台进程吗?
(说不定设置USERNAME和SCHEMANAME两个字段的目的就是要区分出这些USERNAME为空的记录哦)

解决方案 »

  1.   

    有区别啊,还是看了你博客里关于user和schema的区别,现在还记得比较深刻
    可以试试
    alter session set current_schema=XX;
    然后再查询
    select paddr,user#,username,schema#,schemaname from v$session where schemaname<>usernameOracle内部进程的username为空
      

  2.   

    呵呵 
    SCHEMA和USER的区别我是知道 可是不知道还有alter session set current_schema=XX; 这条语句
    这下都清楚了
    做了个实验 
    贴出来看看
    SQL> create user tt1 identified by tt1;User created.SQL> grant connect,resource to tt1;Grant succeeded.SQL> conn tt1/tt1
    Connected.
    SQL> create table dept(id number);Table created.SQL> insert into dept values(1);1 row created.SQL> commit;Commit complete.SQL> select * from dept;        ID
    ----------
             1SQL> alter session set current_schema=scott;Session altered.SQL> select * from dept;
    select * from dept
                  *
    ERROR at line 1:
    ORA-00942: table or view does not exist
    SQL> conn scott/tiger
    Connected.
    SQL> grant select on dept to tt1;Grant succeeded.SQL> conn tt1/tt1
    Connected.
    SQL> select * from dept;        ID
    ----------
             1SQL> alter session set current_schema=scott;Session altered.SQL> select * from dept;    DEPTNO DNAME          LOC
    ---------- -------------- -------------
            10 ACCOUNTING     NEW YORK
            20 RESEARCH       DALLAS
            30 SALES          CHICAGO
            40 OPERATIONS     BOSTONSQL>
      

  3.   

    CURRENT_SCHEMA
    Syntax:CURRENT_SCHEMA = schemaThe CURRENT_SCHEMA parameter changes the current schema of the session to the specified schema. Subsequent unqualified references to schema objects during the session will resolve to objects in the specified schema. The setting persists for the duration of the session or until you issue another ALTER SESSION SET CURRENT_SCHEMA statement.This setting offers a convenient way to perform operations on objects in a schema other than that of the current user without having to qualify the objects with the schema name. This setting changes the current schema, but it does not change the session user or the current user, nor does it give you any additional system or object privileges for the session.
      

  4.   


    这里为什么要设置USER#和SCHEMA#,USERNAME和SCHEMANAME呢?内容是差不多一样的呀。
    user# schema#是ID
    username schemaname是Name 

    当然,还有一些不一样的地方,就是那些SCHEMANAME为SYS,但USERNAME为空的那些进程,都是些后台进程吗? 
    (说不定设置USERNAME和SCHEMANAME两个字段的目的就是要区分出这些USERNAME为空的记录哦)
    是的,为null的是后天进程