oracle 常用操作/常用查詢

1. 用戶創建/刪除
create user ims identified by huawei default tablespace users;
grant dba to ims;
drop user ims cascade;


2. 用戶修改密碼/解鎖
alter user scott account unlock identified by tiger;


3. dmp導入/導出
--導出數據庫的全部數據
exp ims/huawei@IMSSPG file=/home/oracle4spg/all.dmp full=y
--導出指定用戶的數據
exp ims/huawei@IMSSPG file=/home/oracle4spg/ims_scott.dmp owner=ims,scott
--導出指定的表
exp ims/huawei@imsspg file=/home/oracle4spg/tables.dmp tables=ims.ims_business_type

--導入全部數據
imp ims/huawei@IMSSPG file=/home/oracle4spg/all.dmp full=y
--導入指定的表
imp ims/huawei@IMSSPG file=/home/oracle4spg/all.dmp tables=ims.ims_business_type
--導入指定的用戶
imp ims/huawei@IMSSPG file=/home/oracle4spg/all.dmp fromuser=ims,scott
--將一個用戶所屬的數據導入另一個用戶
imp ims/huawei@IMSSPG file=/home/oracle4spg/all.dmp fromuser=ims touser=scott


4. 數據字典-常用查詢
select username from all_users;--查詢所有用戶
select * from user_role_privs;--查詢當前用戶角色
select table_name from user_tables;--查詢用戶的表
select table_name from all_tables;--查詢用戶可訪問的表


5. insert語句--子查詢
insert into dept(id,name) select deptno, dname from dept;


6. 刪除重複記錄
delete from emp2 t1 where exists (select * from emp2 t2 where t1.id>t2.id and t1.ename=t2.ename);


7. 查看數據庫的連接的實例名
select * from  v$instance;


8. 已使用 TNSNAMES 適配器來解析別名
oracle4spg@omu10:/root> tnsping imsspg

TNS Ping Utility for Linux: Version 11.1.0.6.0 - Production on 19-SEP-2012 06:58:10

Copyright (c) 1997, 2007, Oracle.  All rights reserved.

Used parameter files:
/opt/oracle4spg/oradb/11g/network/admin/sqlnet.ora


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (address=(protocol=tcp)(host=172.40.128.88)(port=1531)) (LOAD_BALANCE = no) (FAILOVER = yes)) (CONNECT_DATA = (SERVICE_NAME = IMSSPG)))
OK (0 msec)
oracle4spg@omu10:/root>



發佈了54 篇原創文章 · 獲贊 36 · 訪問量 9萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章