Oracle常用命令总结

--创建表空间

create tablespace 表空间名 datafile 'D:\TEST.DBF' size 1000M autoextend on next 100M;

--扩展表空间

alter tablespace 表空间名 add datafile ‘D:\TEST01.DBF’ size 1000M autoextend on next 100M maxsize unlimited;

--创建用户并制定表空间

create user TEST identified by 密码 default tablespace 表空间名 temporary tablespace TEMP profile DEFAULT password expire;

--修改用户对应的表空间

alter user TEST default tablespace 表空间名

--授权操作

grant dba to TEST;

grant unlimiten tablespace to TEST:

grant resource,connect to TEST;

--修改用户密码

alter user TEST identified by 密码;

--解锁用户

alter user 用户名 account unlock;

--导出用户表结构

exp TEST/test@localhost:1521/orcl file=D:\data.dmp owner=TEST rows=n;

--导出部分数据

exp TEST/test@localhost:1521/orcl file=D:\data.dmp statistics=none tables(DEPT) query=\"where rownum<100\";

--导入数据

imp TEST/test@localhost:1521/orcl file=D:\data.dmp log=D:\import.log full=y ignore=y;

--用expdp导出数据

expdp TEST/test@localhost:1521/orcl dumpfile=expdata.dmp logfile=expdata.log;

--用impdp导入数据库

impdp TEST/test@localhost:1521/orcl dumpfile=expdata.dmp logfile=import.log;

--查询数据文件的状态

select file#,name,status from v$datafile;

--删除用户
drop user 用户名称 cascade;
--删除表空间及对应的表空间文件也删除掉
drop tablespace 表空间名称 including contents and datafiles cascade constraint;

alter database datafile ‘/oracle/product/10.2/db_1/dbs/ AAAAAAAA’ offline drop;

select file#,name,status from v$datafile;

--查看用户和默认表空间的关系
select username,default_tablespace from dba_users;
--查看当前用户能访问的表
select * from user_tables; 
--Oracle查询用户表
select * from user_all_tables;

--Oracle查询用户视图
select * from user_views;
--查询所有函数和储存过程:
select * from user_source;
--查询所有用户:
select * from all_users;
--select * from dba_users
--查看当前用户连接:
select * from v$Session;
--查看用户角色
SELECT * FROM USER_ROLE_PRIVS;
--查看当前用户权限:
select * from session_privs;
--查看所有用户所拥有的角色
SELECT * FROM DBA_ROLE_PRIVS;
--查看所有角色
select * from dba_roles;
--查看数据库名
SELECT NAME FROM V$DATABASE;
--查看所有表空间使用情况

select a.file_id "FileNo",
       a.tablespace_name "Tablespace_name",
       a.bytes "Bytes",
       a.bytes - sum(nvl(b.bytes, 0)) "Used",
       sum(nvl(b.bytes, 0)) "Free",
       sum(nvl(b.bytes, 0)) / a.bytes * 100 "%free"
  from dba_data_files a, dba_free_space b
 where a.file_id = b.file_id(+)
 group by a.tablespace_name, a.file_id, a.bytes
 order by a.tablespace_name;




select a.tablespace_name,
       total,
       free,
       total - free as used,
       substr(free / total * 100, 1, 5) as "FREE%",
       substr((total - free) / total * 100, 1, 5) as "USED%"
  from (select tablespace_name, sum(bytes) / 1024 / 1024 / 1024 as total
          from dba_data_files
         group by tablespace_name) a,
       (select tablespace_name, sum(bytes) / 1024 / 1024 / 1024 as free
          from dba_free_space
         group by tablespace_name) b
 where a.tablespace_name = b.tablespace_name
 order by a.tablespace_name;

Oracle数据库生成UUID

select sys_guid() from dual;

--Oracle 查重

select * from 表 where Id in (select Id from 表 group by Id having count(Id) > 1)

/*在数据库服务器上查看服务器的服务名*/

C:\WINDOWS\system32>lsnrctl status

--Oracle序列相关

-- Create sequence 
create sequence seq_userid
minvalue 1
maxvalue 999999
start with 1
increment by 1;

--增加序列,自增序列,规定位数,不足用0补足
--比如下一个序列为5,查出效果为00005
select (lpad(SEQ_TEST.nextval, 6, '0')) startcode from dual;

--查看当前用户下的所有序列:
select * from user_sequences;
--查看所有用户下的所有序列:
select * from all_sequences;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值