常用SQL 备忘

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/winteriscomming/article/details/88948194
impdp 'sys/root@XE as sysdba' dumpfile=IBOM_V3.2.1_171205.dmp

imp CHAO/APP@XE file="C:\oraclexe\app\oracle\admin\XE\dpdump\IBOM_V3.2.1_171205.dmp" full="y"

imp sys/root@XE as sysdba file="C:\oraclexe\app\oracle\admin\XE\dpdump\IBOM_V3.2.1_171205.dmp" full="y"

impdp 'CHAO/APP@XE as sysdba' dumpfile=IBOM_V3.2.1_171205.dmp

drop user ×× cascade


impdp 'sys/root@XE as sysdba' dumpfile=BYD201808271802BYD.dmp

--访问
sqlplus root/admin123@//10.192.39.122:1522/XE


--导出
1.
—————ssh [email protected] -p 1822    #(先登录到远程数据库系统)
—————expdp 'system/[email protected]:1522/XE'  dumpfile=Gant_XPBOM_201903071758_D.DMP schemas=CORE,MSTDATA,BOMMGMT,CFGMGMT,CHGMGMT,CUST,INTEGRATION  #导出语句
—————/u01/app/oracle/admin/XE/dpdump    #(dump文件的存放路径)
2.
expdp 'sys/app@localhost:1521/xe as sysdba' dumpfile=bydui_20180129.dmp directory=DATA_PUMP_DIR schemas=CORE,MSTDATA,BOMMGMT,CFGMGMT,CHGMGMT,INTEGRATION,CUST


--导入		
--通用:
impdp 'system/pengchao520@XE' schemas=BOMMGMT,CFGMGMT,CHGMGMT,CORE,CUST,MSTDATA,INTEGRATION dumpfile=xbom_2019_03_18_00_00_01.dmp  content=ALL
impdp system/oracle@XE dumpfile= xbom_2019_03_07_19_47_07.dmp schemas=CORE,MSTDATA,BOMMGMT,CFGMGMT,CHGMGMT,CUST,INTEGRATION EXCLUDE=STATISTICS
impdp 'system/pengchao520@XE as sysdba' schemas=BOMMGMT,CFGMGMT,CHGMGMT,CORE,CUST,MSTDATA dumpfile=Gant_XPBOM_201903061758_D.DMP  content=ALL
impdp system/pengchao520@XE dumpfile = XP201804291702.DMP schemas=CORE,MSTDATA,BOMMGMT,CFGMGMT,CHGMGMT,CUST,INTEGRATION EXCLUDE=STATISTICS
1.
impdp 'sys/app@localhost:1521/xe as sysdba' dumpfile=BYD201807090900BAK.DMP directory=DATA_PUMP_DIR schemas=CORE,MSTDATA,BOMMGMT,CFGMGMT,CHGMGMT,INTEGRATION,CUST remap_tablespace=USERS:USERS
2.
impdp system/oracle@XE transform=segment_attributes:n dumpfile = 64_gant_201902181610.DMP schemas=CORE,MSTDATA,BOMMGMT,CFGMGMT,CHGMGMT,CUST,INTEGRATION  EXCLUDE=STATISTICS
3.
impdp 'sys/app@localhost:1521/xe as sysdba' dumpfile=60_BYDBOM_20180411_D.DMP directory=DATA_PUMP_DIR schemas=CORE,MSTDATA,BOMMGMT,CFGMGMT,CHGMGMT remap_tablespace=USERS:USERS EXCLUDE=STATISTICS

impdp system/admin@XE dumpfile ="C:\oraclexe\app\oracle\admin\XE\dpdump\BYD201806061753BAK.DMP" schemas=CORE,MSTDATA,BOMMGMT,CFGMGMT,CHGMGMT,CUST EXCLUDE=STATISTICS

create or replace directory dumpdir as '/home/dumpfiles';


impdp system/admin@XE transform=segment_attributes:n dumpfile = BYDTest20190103090600.DMP directory=BYDKC schemas=CORE,MSTDATA,BOMMGMT,CFGMGMT,CHGMGMT,CUST,INTEGRATION,INTERMEDIATE

--删除用户命令:
drop user mstdata cascade;

drop user bommgmt cascade;
drop user cfgmgmt cascade;

drop user chgmgmt cascade;
drop user cust cascade;
drop user core cascade;

drop user integration cascade;
drop user intermediate cascade;

--数据库表锁死处理相关sql
select 'alter system kill session '|| ''''||t2.sid ||','|| ''||t2.serial#||''''
  from v$locked_object t1, v$session t2, dba_objects t3
 where t1.session_id = t2.sid
   and t1.object_id = t3.object_id
 order by t2.logon_time;


--杀进程结束会话:
select 'alter system kill session ''' || sid || ',' || serial# || ''';' from v$session where username='CORE';

--扩展表空间
---查询表空间使用情况
SELECT dbf.tablespace_name, dbf.totalspace "总量(M)", dbf.totalblocks AS 总块数, dbf.totalspace - dfs.freespace As "已使用总量(M)", dfs.freespace "剩余总量(M)", dfs.freeblocks "剩余块数", ((dbf.totalspace - dfs.freespace) / dbf.totalspace) * 100 AS "已使用百分比%", (dfs.freespace / dbf.totalspace) * 100 "空闲比例%"
FROM(
	SELECT
	T.tablespace_name,
	SUM(T.bytes) / 1024 / 1024 totalspace,

	SUM(T.BLOCKS)totalblocks
	FROM
	dba_data_files T
	GROUP BY
	T.tablespace_name)dbf,
(
	SELECT
	tt.tablespace_name,
	SUM(tt.bytes) / 1024 / 1024 freespace,
	SUM(tt.BLOCKS)freeblocks
	FROM
	dba_free_space tt
	GROUP BY
	tt.tablespace_name)dfs
WHERE
TRIM(dbf.tablespace_name) = TRIM(dfs.tablespace_name)
-- 查看临时表空间使用情况
SELECT tbs 表空间名, SUM(totalM) 总共大小M, SUM(usedM) 已使用空间M, SUM(remainedM) 剩余空间M, SUM(usedM) / SUM(totalM) * 100 已使用百分比, SUM(remainedM) / SUM(totalM) * 100 剩余百分比
FROM (
  SELECT tb.file_id ID, tb.tablespace_name tbs, tb.file_name NAME, tb.bytes / 1024 / 1024 totalM, (tb.bytes - SUM(NVL(ta.free_space, 0))) / 1024 / 1024 usedM,
    SUM(NVL(ta.free_space, 0) / 1024 / 1024) remainedM, SUM(NVL(ta.free_space, 0) /(tb.bytes) * 100), (100 - (SUM(NVL(ta.free_space, 0)) /(tb.bytes) * 100))
  FROM dba_temp_free_space ta, dba_temp_files tb
  WHERE ta.tablespace_name = tb.tablespace_name
  GROUP BY tb.tablespace_name, tb.file_name, tb.file_id, tb.bytes
  ORDER BY tb.tablespace_name
) GROUP BY tbs;

-- 查看表空间使用情况
SELECT tbs 表空间名, SUM(totalM) 总共大小M, SUM(usedM) 已使用空间M, SUM(remainedM) 剩余空间M, SUM(usedM) / SUM(totalM) * 100 已使用百分比, SUM(remainedM) / SUM(totalM) * 100 剩余百分比
FROM (
  SELECT tb.file_id ID, tb.tablespace_name tbs, tb.file_name NAME, tb.bytes / 1024 / 1024 totalM, (tb.bytes - SUM(NVL(ta.bytes, 0))) / 1024 / 1024 usedM,
    SUM(NVL(ta.bytes, 0) / 1024 / 1024) remainedM, SUM(NVL(ta.bytes, 0) /(tb.bytes) * 100), (100 - (SUM(NVL(ta.bytes, 0)) /(tb.bytes) * 100))
  FROM dba_free_space ta, dba_data_files tb
  WHERE ta.file_id = tb.file_id
  GROUP BY tb.tablespace_name, tb.file_name, tb.file_id, tb.bytes
  ORDER BY tb.tablespace_name
) GROUP BY tbs;

---查询表空间自身信息
SELECT tablespace_name,file_id,file_name,
ROUND(bytes / (1024 * 1024), 0)total_space
FROM dba_data_files
ORDER BY tablespace_name
---修改表空间
alter database datafile '上面语句查到的file_name' resize 2000m;
---设置表空间自增长
alter database datafile '上面语句查到的file_name' autoextend on next 100m maxsize 10000m;



drop user core cascade;
drop user MSTDATA cascade;
drop user BOMMGMT cascade;
drop user CFGMGMT cascade;
drop user CHGMGMT cascade;
drop user INTEGRATION cascade;
drop user CUST cascade;

create user CORE identified by APP;
create user MSTDATA identified by APP;
create user BOMMGMT identified by APP;
create user CFGMGMT identified by APP;
create user CHGMGMT identified by APP;
create user INTEGRATION identified by APP;
create user CUST identified by APP;

grant dba to CORE;
grant dba to MSTDATA;
grant dba to BOMMGMT;
grant dba to CFGMGMT;
grant dba to CHGMGMT;
grant dba to INTEGRATION;
grant dba to CUST;

猜你喜欢

转载自blog.csdn.net/winteriscomming/article/details/88948194