oracle資料庫常用命令

來源:互聯網
上載者:User

標籤:bst   oid   oracl   return   add   ant   files   interface   flashback   

create tablespace GRP
datafile ‘E:/GRP_TBSPACE.dbf‘
size 3000M
autoextend on next 5M maxsize 5000M;


/*第3步:建立使用者並指定資料表空間 */
create user tctest0707 identified by a default tablespace GRP temporary tablespace temp profile default;

/*第4步:給使用者授予許可權 */
grant connect,resource,dba,select any table to tctest0707;
GRANT select ANY TABLE TO nncz2017 WITH ADMIN OPTION;(常態庫執行)
--開始->運行->輸入cmd->imp tctest0707/[email protected]:1521/orcl full=y file=


-----11g匯入到10g
pm_db01 / szxmk16
--impdp nsxmk16/[email protected] dumpfile=NSXMK16062001.dmp logfile=NSXMK16062001.log remap_schema=nsxmk16:nsxmk16 transform=oid:n version=10.2.0.1.0
remap_tablespace=qjhxtbs:szxmktbs
--匯入檔案放在F:\oracle\product\10.2.0\admin\orcl\dpdump

--(導深圳11G庫 建立資料表空間)
create tablespace SZXMKTBS
datafile ‘D:\app\yanchao\oradata\orcl\SZXMKTBS.dbf‘ size 1000m autoextend on next 10m ;
create tablespace GRP
datafile ‘D:\app\yanchao\oradata\orcl\GRP.dbf‘ size 1000m autoextend on next 10m ;
create tablespace SHENZHENDB
datafile ‘D:\app\yanchao\oradata\orcl\SHENZHENDB.dbf‘ size 1000m autoextend on next 10m ;

--匯出資料庫
exp nncz2017/[email protected]/nncz owner=nncz2017 file=F:\nncz2017.dmp;


--修改資料庫大小
alter database datafile ‘E:\GRP_TBSPACE.DBF‘ resize 10240m

----閃回資料

select sysdate 時間, timestamp_to_scn(to_date(‘2017-09-01 17:20:31‘,‘yyyy-MM-dd hh24:mi:ss‘)) SCN from dual

alter table ydz_exi_budget_trans enable row movement

flashback table ydz_exi_budget_trans to scn 29127907


----查詢閃回資料:
select * from sal_person as of timestamp to_date(‘2012-04-27 15:00:00‘,‘YYYY-MM-DD HH24:MI:SS‘)


--查詢重複資料
select * from gfm_ps_uv_view a where rowid !=(select max(rowid)

  from gfm_ps_uv_view b where a.template_id=b.template_id and a.menu_id=b.menu_id and a.class_name = b.class_name and a.assembly_name = b.assembly_name ) order by view_id;

--添加欄欄位、列注釋
alter table gfm_ps_pfs_interface add c1 number ;
comment on column gfm_ps_pfs_interface.c1 is ‘測試‘;
alter table gfm_ps_pfs_interface drop column c1;--不會刪除列注釋

 

--查詢某個欄位在哪個表的哪個列
select table_name,column_name from user_tab_columns where column_name like ‘%ACTION_CODE%‘;


--建立job自動執行預存程序(命令模式)
declare
Job_InitJk pls_integer;
begin
sys.dbms_job.submit(job => Job_InitJk,
what => ‘Pro_InitInterfaceTable;‘,
next_date => sysdate,
interval => ‘TRUNC(SYSDATE+1)+6/24‘);
commit;
end;


--

/**
* Object數群組轉換為List(推薦使用)
*
* @param arr 數組
* @return List
*/
public static List array2List2(Object[] arr) {
List list = new ArrayList();
if (arr == null) return list;
list = Arrays.asList(arr);
return list;
}

--無法刪除當前串連的使用者
drop user WZCZ2016 cascade


DROP TABLESPACE GRP INCLUDING CONTENTS AND DATAFILES;
drop tablespace GRP including contents and datafiles cascade constraints;


select owner,table_name,tablespace_name from dba_tables
where tablespace_name=‘GRP‘
and table_name in (select mview_name from dba_mviews);

 

 

--oracle中使用者刪除不了,ORA-01940提示 “無法刪除當前已連線的使用者”
select username,sid,serial# from v$session where username=‘WZCZ2016‘

alter system kill session ‘137,41‘;

alter system kill session‘201,14034‘;

 

--之後可以刪除使用者

drop user WZCZ2016 cascade;

--查看錶空間情況

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


--去Null 字元
update lyz_ls set tt=rtrim(tt,chr(0))
--截取某個字元最後出現的位置之後的字串
substr(a.parent_sr,instr(a.parent_sr,‘.‘,-1)+1)


--查詢某個表被那個視圖引用了
select * from dba_dependencies A where REFERENCED_NAME=‘GFM_PS_PFS‘ and TYPE=‘VIEW‘

oracle資料庫常用命令

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.