如何创建一个视图,其中收集了有关在 ORACLE 中使用该视图的人员的所有数据?
How to create a view where all data are collected concerning the person who uses the view in ORACLE?
数据应该来自tableEmp
和另一个tableDept
和Salgrade
。假设通过constantuser可以得到用户的标识符(查看查询结果:SELECT User FROM Dual;
)与值Ename
相同。我想在 tableEmp
中使用自己的标识符作为 Ename
.
创建一行
数据库:
电磁脉冲
EMPNO | ENAME | JOB | MGR | HIREDATE | SAL | COMM |DEPTNO
----- ------- --------- ---- --------- ----- ---- ------
7839 KING PRESIDENT NULL 17-NOV-81 5000 NULL 10
7698 BLAKE MANAGER 7839 01-MAY-81 2850 NULL 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 NULL 10
7566 JONES MANAGER 7839 02-APR-81 2975 NULL 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7900 JAMES CLERK 7698 03-DEC-81 950 NULL 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7902 FORD ANALYST 7566 03-DEC-81 3000 NULL 20
7369 SMITH CLERK 7902 17-DEC-80 800 NULL 20
7788 SCOTT ANALYST 7566 09-DEC-82 3000 NULL 20
7876 ADAMS CLERK 7788 12-JAN-83 1100 NULL 20
7934 MILLER CLERK 7782 23-JAN-82 1300 NULL 10
部门
DEPTNO | DNAME | LOC
------ ----------- --------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
萨尔格莱德
GRADE | LOSAL | HISAL
----- ----- -----
1 700 1200
2 1201 1400
3 1401 2000
4 2001 3000
5 3001 9999
这些表归用户所有 SCOTT
所以 - 连接它; Scott 将创建一个视图并授予其他用户 select
对 public 同义词的权限。
SQL> connect scott/tiger
Connected.
SQL> create or replace view v_emp as
2 select d.deptno, d.dname, e.empno, e.ename, e.job
3 from emp e join dept d on e.deptno = d.deptno
4 where e.ename = user;
View created.
SQL> create public synonym psyn_v_emp for v_emp;
Synonym created.
SQL> grant select on psyn_v_emp to public;
Grant succeeded.
好的;那么,楼主看到了什么?
SQL> show user
USER is "SCOTT"
SQL> select * from psyn_v_emp;
DEPTNO DNAME EMPNO ENAME JOB
---------- -------------- ---------- ---------- ---------
20 RESEARCH 7788 SCOTT ANALYST
-----
Scott sees only Scott's data
以其他用户身份连接(我之前创建了名为 KING
的用户):
SQL> connect king/king
Connected.
SQL> show user
USER is "KING"
SQL> select * from psyn_v_emp;
DEPTNO DNAME EMPNO ENAME JOB
---------- -------------- ---------- ---------- ---------
10 ACCOUNTING 7839 KING PRESIDENT
-----
King sees only King's data
SQL>
因此,如果我明白你在问什么,那就是“它”。
数据应该来自tableEmp
和另一个tableDept
和Salgrade
。假设通过constantuser可以得到用户的标识符(查看查询结果:SELECT User FROM Dual;
)与值Ename
相同。我想在 tableEmp
中使用自己的标识符作为 Ename
.
数据库:
电磁脉冲
EMPNO | ENAME | JOB | MGR | HIREDATE | SAL | COMM |DEPTNO
----- ------- --------- ---- --------- ----- ---- ------
7839 KING PRESIDENT NULL 17-NOV-81 5000 NULL 10
7698 BLAKE MANAGER 7839 01-MAY-81 2850 NULL 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 NULL 10
7566 JONES MANAGER 7839 02-APR-81 2975 NULL 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7900 JAMES CLERK 7698 03-DEC-81 950 NULL 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7902 FORD ANALYST 7566 03-DEC-81 3000 NULL 20
7369 SMITH CLERK 7902 17-DEC-80 800 NULL 20
7788 SCOTT ANALYST 7566 09-DEC-82 3000 NULL 20
7876 ADAMS CLERK 7788 12-JAN-83 1100 NULL 20
7934 MILLER CLERK 7782 23-JAN-82 1300 NULL 10
部门
DEPTNO | DNAME | LOC
------ ----------- --------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
萨尔格莱德
GRADE | LOSAL | HISAL
----- ----- -----
1 700 1200
2 1201 1400
3 1401 2000
4 2001 3000
5 3001 9999
这些表归用户所有 SCOTT
所以 - 连接它; Scott 将创建一个视图并授予其他用户 select
对 public 同义词的权限。
SQL> connect scott/tiger
Connected.
SQL> create or replace view v_emp as
2 select d.deptno, d.dname, e.empno, e.ename, e.job
3 from emp e join dept d on e.deptno = d.deptno
4 where e.ename = user;
View created.
SQL> create public synonym psyn_v_emp for v_emp;
Synonym created.
SQL> grant select on psyn_v_emp to public;
Grant succeeded.
好的;那么,楼主看到了什么?
SQL> show user
USER is "SCOTT"
SQL> select * from psyn_v_emp;
DEPTNO DNAME EMPNO ENAME JOB
---------- -------------- ---------- ---------- ---------
20 RESEARCH 7788 SCOTT ANALYST
-----
Scott sees only Scott's data
以其他用户身份连接(我之前创建了名为 KING
的用户):
SQL> connect king/king
Connected.
SQL> show user
USER is "KING"
SQL> select * from psyn_v_emp;
DEPTNO DNAME EMPNO ENAME JOB
---------- -------------- ---------- ---------- ---------
10 ACCOUNTING 7839 KING PRESIDENT
-----
King sees only King's data
SQL>
因此,如果我明白你在问什么,那就是“它”。