Oracle简单的增删改查

    用户本身管理
        增
            create user C##jaovo identified by jaovo123;    //sys,system
            密码必须以字母开头
        删
            不能自己删除自己
            删除要门是DBA,或者drop user权限
            drop user C##用户名 cascade;
            如果要删除的用户下已经有表,就必须带有参数cascade会把表和用户一起删除
        改
            修改自己密码: password ;    //系统用户,或者有alter权限
            给别人修改密码,据需要权限:dba或者alter user权限
            alter user c##scott identified by root;
            password 用户名(新版本不能使用)
        查
            当前用户下所有的表:select * from user_tables;
            显示当前数据库的所有表:select * from tab;
            select * from dba_users; 查看数据库里面所有用户,前提是你是有dba权限的帐号,如sys,system
select * from all_users;  查看你能管理的所有用户!
select * from user_users; 查看当前用户信息 !
    用户权限管理
        基本原理
            什么是权限:就是你能不能操作某条SQL语句
            系统权限(用户管理权限)
                140多个
            对象权限
                用户对不属于他的数据对象进行操作的权限(其他用户的数据操作的权限,跨部门)
                20多个
            授权关键字:grant
            创建关键字:create
        增
            grant connect to C##用户名
            grant 操作名 on 表名 to 用户名;
                表操作:增删改查/所有,select,update,insert,delete,all
            grant 操作名 on 表名 to 用户名 with grant option;
                该权限可以有被授予者授予给别人
                权限的传递
        删
            收回赋予给某个用户的权限,(三个用户)
            级联授权的,会级联收回
            revoke 操作名 on 表名 from 用户名
            revoke select on emp from us_test;
    用户综合管理案例
        1 创建用户,默认创建在哪个数据库里面,但是默认没有任何权限,不能登录任何数据库的,需要授权
        2 为其制定相应的权限,需要sys/system用户赋予权限
grant connect to miaoming
        4 grant resource to xiaoming;
        grant unlimited tablespace to xiaoming;
        select * from user_tables
        3  create table TestTable(userId varchar2(30),userName varchar2(30));
        5 查看表的列:desc test;
        6 grant select on c##scott.emp to xiaoming;(sys,system,表所有者,scott)
        insert into  c##scott.emp(userId,userName) values(123,hello);
        7 select * from c##scott.emp;
        8 收回权限(有权限的人都可以收回):revoke select on emp from xiaoming
        9 权限传递:grant select on emp to xiaoming with grant option
        10 如果授权在上级被会收,下一级也会被回收
        11 把测试用户删除掉:drop user C##用户名 cascade;
    用户密码管理(profile)
        profile:用户密码管理文件,用于强制对用户密码进行管理,步骤是创建文件,赋予文件
        数据库创建时,会自动创建默认的profile选项:default,建立用户是如果没有指定profile选项,就会分配default
        用户锁定
            创建规则,使用规则
                用户尝试3次锁定两天:lock_account:可变,3,2可变
                create profile c##lock_account limit failed_login_attempts3 password_lock_time 2;
                指定限制给某个用户:alter user xiaoming profile aaa;
            解锁:alter user 用户名 account unlock;解锁(系统用户)
        强制改密码(终止口令).dba身份
            create profile 规则名 limit password_life_time 10 password_grace_time 天数;
            alter user 用户名 profile 规则名
        密码强度和密码历史
            create profile password_history(规则名) limit password_life_time 10密码有效天数 password_grace_time 2宽限天数 password_reuse_time 10可再用天数;
            alter user 用户名 profile 规则名
        增
            create profile 规则名称 limit failed_login_attempts 错误次数 password_lock_time 锁定天数
            alter user 用户名 profile 规则名;    //加锁
            alter user 用户名 account unlock;    //解锁
        删
            drop profile password_history/名字 (cascade);    //所有用户不在约束
    密码管理综合案例
        create user c##jaovo
        2 锁定密码
            1 创建规则
                create profile drop profile password_history/名字 (cascade);t limit failed_login_attempts3 password_lock_time 2;
            2 指定规则
                alter user 用户名 profile 规则名
            3 输错密码
            4 级联删除规则:
                drop profile password_history/名字 (cascade);
        3 强制修改密码
            1 创建规则
                create profile password_history(规则名) limit password_life_time 10密码有效天数 password_grace_time 2宽限天数 password_reuse_time 10可再用天数;
            2 指定规则
                alter user 用户名 profile 规则名
            4 级联删除规则:
                drop profile password_history/名字 (cascade);    //所有用户不在约束
        4 删除用户
    基于角色的权限管理
        基本原理
            和linux操作系统权限控制差不多
            把各个权限打包,继承到某个角色上,给用户赋予这个角色,用户就拥有了这些权限.
        重要角色
            预定义角色
                resource
                    数据库内部资源操作权限
                connect
                    连接权限
                dba
                    数据库管理员权限
           

原文地址:https://www.cnblogs.com/xrmqbl804915256/p/4774606.html