Oracle常用語句

2021-07-31 11:10:46 字數 1737 閱讀 6722

create public database link 鏈結名

connect to 使用者名稱 identified by 密碼

using '(description =(address_list =(address =(protocol = tcp)(host = 資料庫url)(port = 資料庫埠)))(connect_data =(sid = 資料庫標識)))';

舉例:create public database link my_link

connect to scott identified by 123456

using '(description =(address_list =(address =(protocol = tcp)(host = 127.0.0.1)(port = 1521)))(connect_data =(sid = orcl)))';

select * from dba_db_links;

drop public database link 鏈結名;

舉例:drop public database link my_link;

create table 表名

asselect * from 使用者名稱.表名@鏈結名;

舉例:create table my_table as select * from scott.my_table@my_link;

5.匯出資料庫(生成dmp檔案):

exp 使用者名稱/密碼@資料庫ip:埠/資料庫標識 file=dmp檔案位置

舉例:exp scott/[email protected]:1521/orcl file=e:/my_database.dmp (本機ip和埠可省略)

6.匯入資料庫:

imp 使用者名稱/密碼@資料庫ip:埠/資料庫標識 file=dmp檔案位置 full=y

舉例:imp scott/[email protected]:1521/orcl file=e:/my_database.dmp full=y(本機ip和埠可省略)

7.建立新使用者:

create user 使用者名稱 identified by 密碼;

grant dba to 使用者名稱;

舉例:create user my identified by 123456;

grant dba to my;

8.update一張表的某些字段根據另外一張表:

update 表1 set (列1,列2,...) = (select (列1,列2) from 表2 where 表1.主鍵=表2.主鍵);

舉例:update student set (name) = (select name from user where student.id=user.id);

update student set name = (select name from scott.user@my_link where student.id=scott.user.id@my_link;(利用資料庫鏈結)

9.檢視本資料庫中所有的表:

select table_name from user_tables;

10.查詢一張表中的所有列:

select column_name from all_tab_cols where table_name = '表名' and owner = '使用者名稱';

舉例:select column_name from all_tab_cols where table_name = 'user' and owner = 'scott';

oracle 常用語句

oracle 產看表空間 select total.name tablespace name free space,total space free space used space,total space from select tablespace name,sum bytes 1024 102...

oracle常用語句

drop tablespace crm online space including contents and datafiles 刪除表空間 drop user wuliu01 cascade 刪除使用者 exp orcl file d dmp 匯出資料庫 imp orcl file e alen...

oracle 常用語句

oracle 常用語句 查詢表的大小 select t.owner,t.segment name,sum t.blocks 8 1024 m as s,t.segment type from dba segments t where t.owner user name group by t.owne...