Oracle数据库下的一些常用的sql语句

oracle查询当前用户名下所有表

select * from all_tables where owner='TEST';

查看当前登录的用户的表:

  select table_name from user_tables;

登录

运行cmd进入命令行

  Sqlplus 用户名/密码 [as sysdba]

image
如果是超级管理员需要在用户名/密码后面加上 as sysdba,是以系统管理员的身份来登录的,如图。
image
如果是普通用户不需要as sysdba

2. 查看当前连接数据库的用户

使用show user查看当前的用户
image

3. 用户的切换

在登录的状态下输入:conn 用户名/密码 [as sysdba]

如图:
Ø 切换为超级管理员
image
Ø 切换为普通的用户
image

4. 查看用户下的表

为了防止命令行中数据展示表格错乱的情况可以设计行宽和列宽

        Set  linesize 300;         每行展示300个字符

        Col列名          for  a[数字],某一列占几个字符

在用户登录的情况下输入:

select * from tab;

image

创建用户

create user test identified by test;

这样就创建了一个用户名密码都为test的用户 但这个时候test还是不能登陆成功的,我们需要赋予相应的权限

赋予create session 的权限

grant create session to test;
这样test用户就能成功登录进去
 
赋予用户创建表的权限
grant create table to test;
 
赋予相应的权限
grant unlimited tablespace to test;
这个时候用户就拥有了创建表的权限 由于表是用户test的,相应的他就拥有了对创建的表的增删查改的权限了

撤销权限

revoke create table from test;

删除用户

drop user 用户名;

若用户拥有对象,则不能直接删除,否则将返回一个错误值。指定关键字cascade,可删除用户所有的对象,然后再删除用户。

drop user 用户名 cascade;

授权操作

grant select on tabel1 to tabel2; 
grant update on tabel1 to tabel2;

–授权存储过程

grant execute on procedure1 to tabel2;

角色

create role farxix;--建立farxix角色
 
grant insert on table1 to farxix; --将插入表的信息
 
revoke insert on table1 from xujin1; --收回farxix角色的权限
 
grant farxix to farxix1; --将角色的权限授权给farxix1;
 
create role farxix1;
 
grant farxix1 to farxix2; --将角色farxix1授权给farxix2;
 
alter user farxix default farxix1,farxix2; --修改用户默认角色
 
drop role farxix1;--删除角色farxix1;

查看定时任务是否生效


select *
  from dba_scheduler_jobs t
 where t.owner = 'USER'

修改表某列字段长度

alter table 表名 modify name varchar2(60);
alter table 表名 modify (name varchar(60),name1 varchar2(60));

导出dmp文件,防止因为数据为0条而导不出数据


posted @ 2021-07-28 20:56  King-DA  阅读(339)  评论(0)    收藏  举报