oracle操作

Posted 听哥哥的话

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了oracle操作相关的知识,希望对你有一定的参考价值。

--查看并行度
select table_name,degree from user_tables;  
--设置并行
ALTER TABLE   rsk_book_histogram   PARALLEL 2;
--取消并行
ALTER TABLE   rsk_book_histogram   NOPARALLEL;

--删除表空间
DROP TABLESPACE TBNAME INCLUDING CONTENTS AND DATAFILES;
--闪回
SELECT *
FROM etl_column AS OF TIMESTAMP  to_timestamp(2017-11-10 14:05:00, yyyy-mm-dd hh24:mi:ss)
--查询死锁
select sess.sid, 
    sess.serial#, 
    lo.oracle_username, 
    lo.os_user_name, 

    ao.object_name, 
    lo.locked_mode 
    from v$locked_object lo, 
    dba_objects ao, 
    v$session sess 
where ao.object_id = lo.object_id and lo.session_id = sess.sid; 

select * from v$session t1, v$locked_object t2 where t1.sid = t2.SESSION_ID; 
select * from tran_bond_detail;

--杀掉死锁
alter system kill session sid,serial; 




 1.建立表空间,

create tablespace "NETHRA" DATAFILE D:DataBaseOracleiClassiclassiclass.DBF SIZE 100M
AUTOEXTEND   ON   NEXT  10M


2.创建用户并授权
CREATE USER "NETHRA" PROFILE "DEFAULT" IDENTIFIED BY "nethra" DEFAULT TABLESPACE "NETHRA" TEMPORARY TABLESPACE "TEMP" ACCOUNT UNLOCK
GRANT "CONNECT" TO "NETHRA"
GRANT "DBA" TO "NETHRA


3.
exp nethra/[email protected] file=d:iclass20160108.dmp full=y

4.
imp nethra/[email protected] file=d:iclass20160108.dmp full=y


--1G=1024MB 
--1M=1024KB 
--1K=1024Bytes 
--1M=11048576Bytes 
--1G=1024*11048576Bytes=11313741824Bytes 
SELECT a.tablespace_name "表空间名", 
total "表空间大小", 
free "表空间剩余大小", 
(total - free) "表空间使用大小", 
total / (1024 * 1024 * 1024) "表空间大小(G)", 
free / (1024 * 1024 * 1024) "表空间剩余大小(G)", 
(total - free) / (1024 * 1024 * 1024) "表空间使用大小(G)", 
round((total - free) / total, 4) * 100 "使用率 %" 
FROM (SELECT tablespace_name, SUM(bytes) free 
FROM dba_free_space 
GROUP BY tablespace_name) a, 
(SELECT tablespace_name, SUM(bytes) total 
FROM dba_data_files 
GROUP BY tablespace_name) b 
WHERE a.tablespace_name = b.tablespace_name 

5.
alter tablespace HRA_GF
add datafile  D:DATABASEORACLEHRA_DEVGF_STG_TBS21.dbf size 1024M autoextend on ;
6.查看主键索引
select a.constraint_name c,  a.column_name
                                             from user_cons_columns a, user_constraints b
                                             where a.constraint_name = b.constraint_name
                                             and b.constraint_type = P
                                             AND B.owner = {Holworth.Utility.HraUtility.GetDataBaseInfo(AppEnum.Web).user}
                                             and a.table_name = {targetTable}
7.添加主键约束

alter table {targetTable} add constraint pk_{targetTable.Substring(0, len)} primary key({IdField}) 
8.删除主键约束
alter table {targetTable} drop constraint {cname}

 

以上是关于oracle操作的主要内容,如果未能解决你的问题,请参考以下文章

Oracle-常用数据库对象笔记(片段)

Client / Server Interoperability Support Matrix for Different Oracle Versions (Doc ID 207303.1)(代码片段

Oracle数据库从RMAN备份集片段还原指定单个归档日志进行日志挖掘分析

VSCode自定义代码片段——git命令操作一个完整流程

Oracle 数据库 - 使用UEStudio修改dmp文件版本号,解决imp命令恢复的数据库与dmp本地文件版本号不匹配导致的导入失败问题,“ORACLE error 12547”问题处理(代码片段

VSCode自定义代码片段15——git命令操作一个完整流程