ITPub博客

首页 > 数据库 > Oracle > [20201106]11g修改表无需修改权限.txt

[20201106]11g修改表无需修改权限.txt

原创 Oracle 作者:lfree 时间:2020-11-06 15:40:27 0 删除 编辑

[20201106]11g修改表无需修改权限.txt

--//11.2.0.4可以利用with命令修改表而不需要修改权限,做一个演示:

1.环境:
SCOTT@book> @ ver1
PORT_STRING                    VERSION        BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx            11.2.0.4.0     Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

2.建立测试例子:
SCOTT@book> create table empx as select * from emp;
Table created.

create user test identified by test;
grant create session,create table to test;
grant select on scott.empx to test;

3.测试:
--//打开新的session:

TEST@book> show user
USER is "TEST"

TEST@book> select * from scott.empx where rownum=1;
     EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
      7369 SMITH      CLERK           7902 1980-12-17 00:00:00        800                    20


TEST@book> update  scott.empx set sal=sal+100 where empno=7369;
update  scott.empx set sal=sal+100 where empno=7369
              *
ERROR at line 1:
ORA-01031: insufficient privileges

--//仅仅有select权限。

TEST@book> update (select * from scott.empx where empno=7369) set sal=sal+100;
update (select * from scott.empx where empno=7369) set sal=sal+100
                            *
ERROR at line 1:
ORA-01031: insufficient privileges
--//依旧不行。


TEST@book> update (with tmp as (select * from scott.empx where empno=7369) select * from tmp ) set sal=sal+100;

1 row updated.

TEST@book> select * from scott.empx where rownum=1;
     EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
      7369 SMITH      CLERK           7902 1980-12-17 00:00:00        900                    20

--//已经修改了sal=900.

TEST@book> commit ;
Commit complete.

TEST@book> select * from scott.empx where empno=7369;
     EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
      7369 SMITH      CLERK           7902 1980-12-17 00:00:00        900                    20

--//已经生效.


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/267265/viewspace-2732651/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
熟悉oracle相关技术,擅长sql优化,rman备份与恢复,熟悉linux shell编程。

注册时间:2008-01-03

  • 博文量
    4006
  • 访问量
    7969428