可用如下方法復制:

創(chuàng)新互聯(lián)公司作為成都網站建設公司,專注網站建設公司、網站設計,有關企業(yè)網站設計方案、改版、費用等問題,行業(yè)涉及成都玻璃鋼坐凳等多個領域,已為上千家企業(yè)服務,得到了客戶的尊重與認可。
如果新表不存在:
比如有一張表叫test,現(xiàn)在要復制表結構及表內數(shù)據(jù),可執(zhí)行代碼:
create table test as select * from test;
這樣就把表結構連同數(shù)據(jù)一起復制了。
如果表存在,可用以下代碼:
insert into test1 select * from test;commit;
在Internet上運作數(shù)據(jù)庫經常會有這樣的需求 把遍布全國各城市相似的數(shù)據(jù)庫應用統(tǒng)一起來 一個節(jié)點的數(shù)據(jù)改變不僅體現(xiàn)在本地 還反映到遠端 復制技術給用戶提供了一種快速訪問共享數(shù)據(jù)的辦法 一 實現(xiàn)數(shù)據(jù)庫復制的前提條件 數(shù)據(jù)庫支持高級復制功能 您可以用system身份登錄數(shù)據(jù)庫 查看v$option視圖 如果其中Advanced replication為TRUE 則支持高級復制功能 否則不支持 數(shù)據(jù)庫初始化參數(shù)要求 ① db_domain = 指明數(shù)據(jù)庫的域名(默認的是WORLD) 這里可以用您公司的域名 ② global_names = true 它要求數(shù)據(jù)庫鏈接(database link)和被連接的數(shù)據(jù)庫名稱一致 現(xiàn)在全局數(shù)據(jù)庫名 db_name+ +db_domain ③ 有跟數(shù)據(jù)庫job執(zhí)行有關的參數(shù) job_queue_processes = job_queue_interval = distributed_transactions = open_links = 第一行定義SNP進程的啟動個數(shù)為n 系統(tǒng)缺省值為 正常定義范圍為 ~ 根據(jù)任務的多少 可以配置不同的數(shù)值 第二行定義系統(tǒng)每隔N秒喚醒該進程一次 系統(tǒng)缺省值為 秒 正常范圍為 ~ 秒 事實上 該進程執(zhí)行完當前任務后 就進入睡眠狀態(tài) 睡眠一段時間后 由系統(tǒng)的總控負責將其喚醒 如果修改了以上這幾個參數(shù) 需要重新啟動數(shù)據(jù)庫以使參數(shù)生效 二 實現(xiàn)數(shù)據(jù)庫同步復制的步驟 假設在Internet上我們有兩個數(shù)據(jù)庫 一個叫深圳(shenzhen) 一個叫北京(beijing) 具體配置見下表 確認兩臺數(shù)據(jù)庫之間可以互相訪問 在tnsnames ora里設置數(shù)據(jù)庫連接字符串 ① 例如 深圳這邊的數(shù)據(jù)庫連接字符串是以下的格式 beijing = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = )(PORT = )) ) (CONNECT_DATA = (SERVICE_NAME = beijing) ) ) 運行$tnsping beijing 出現(xiàn)以下提示符 Attempting to contact (ADDRESS=(PROTOCOL=TCP)(HOST= )(PORT= )) OK(n毫秒) 表明深圳數(shù)據(jù)庫可以訪問北京數(shù)據(jù)庫 ② 在北京那邊也同樣配置 確認$tnsping shenzhen 是通的 改數(shù)據(jù)庫全局名稱 建公共的數(shù)據(jù)庫鏈接 ① 用system身份登錄shenzhen數(shù)據(jù)庫 SQLalter database rename global_name to cn; 用system身份登錄beijing數(shù)據(jù)庫 SQLalter database rename global_name to ; ② 用system身份登錄shenzhen數(shù)據(jù)庫 SQLcreate public database link using beijing ; 測試數(shù)據(jù)庫全局名稱和公共的數(shù)據(jù)庫鏈接 SQLselect * from global_n cn; 返回結果為就對了 用system身份登錄beijing數(shù)據(jù)庫 SQLcreate public database link cn using shenzhen ; 測試數(shù)據(jù)庫全局名稱和公共的數(shù)據(jù)庫鏈接 SQLselect * from global_na cn; 返回結果為 cn就對了 建立管理數(shù)據(jù)庫復制的用戶repadmin 并賦權 ① 用system身份登錄shenzhen數(shù)據(jù)庫 SQLcreate user repadmin identified by repadmin default tablespace users temporary tablespace temp; SQLexecute dbms_defer_sys register_propagator( repadmin ); SQLgrant execute any procedure to repadmin; SQLexecute dbms_repcat_admin grant_admin_any_repgroup( repadmin ); SQLgrant ment any table to repadmin; SQLgrant lock any table to repadmin; ② 同樣用system身份登錄beijing數(shù)據(jù)庫 運行以上的命令 管理數(shù)據(jù)庫復制的用戶repadmin 并賦權 說明 repadmin用戶名和密碼可以根據(jù)用戶的需求自由命名 在數(shù)據(jù)庫復制的用戶repadmin下創(chuàng)建私有的數(shù)據(jù)庫鏈接 ① 用repadmin身份登錄shenzhen數(shù)據(jù)庫 SQLcreate database link connect to repadmin identified by repadmin; 測試這個私有的數(shù)據(jù)庫鏈接 SQLselect * from global_n cn; 返回結果為就對了 ② 用repadmin身份登錄beijing數(shù)據(jù)庫 SQLcreate database link cn connect to repadmin identified by repadmin; 測試這個私有的數(shù)據(jù)庫鏈接 SQLselect * from global_na cn; 返回結果為 cn就對了 創(chuàng)建或選擇實現(xiàn)數(shù)據(jù)庫復制的用戶和對象 給用戶賦權 數(shù)據(jù)庫對象必須有主關鍵字 假設我們用ORACLE里舉例用的scott用戶 dept表 ① 用internal身份登錄shenzhen數(shù)據(jù)庫 創(chuàng)建scott用戶并賦權 SQLcreate user scott identified by tiger default tablespace users temporary tablespace temp; SQLgrant connect resource to scott; SQLgrant execute on sys dbms_defer to scott; ② 用scott身份登錄shenzhen數(shù)據(jù)庫 創(chuàng)建表dept SQLcreate table dept (deptno number( ) primary key dname varchar ( ) loc varchar ( ) ); ③ 如果數(shù)據(jù)庫對象沒有主關鍵字 可以運行以下SQL命令添加 SQLalter table dept add (constraint dept_deptno_pk primary key (deptno)); ④ 在shenzhen數(shù)據(jù)庫scott用戶下創(chuàng)建主關鍵字的序列號 范圍避免和beijing的沖突 SQL create sequence dept_no increment by start with maxvalue cycle nocache; (說明 maxvalue 可以根據(jù)應用程序及表結構主關鍵字定義的位數(shù)需要而定) ⑤ 在shenzhen數(shù)據(jù)庫scott用戶下插入初始化數(shù)據(jù) SQLinsert into dept values (dept_no nextval accounting new york ); SQLinsert into dept values (dept_no nextval research dallas ); SQLmit; ⑥ 在beijing數(shù)據(jù)庫那邊同樣運行以上① ② ③ ⑦ 在beijing數(shù)據(jù)庫scott用戶下創(chuàng)建主關鍵字的序列號 范圍避免和shenzhen的沖突 SQL create sequence dept_no increment by start with maxvalue cycle nocache; ⑧ 在beijing數(shù)據(jù)庫scott用戶下插入初始化數(shù)據(jù) SQLinsert into dept values (dept_no nextval sales chicago ); SQLinsert into dept values (dept_no nextval operations boston ); SQLmit; 創(chuàng)建要復制的組scott_mg 加入數(shù)據(jù)庫對象 產生對象的復制支持 ① 用repadmin身份登錄shenzhen數(shù)據(jù)庫 創(chuàng)建主復制組scott_mg SQL execute dbms_repcat create_master_repgroup( scott_mg ); 說明 scott_mg組名可以根據(jù)用戶的需求自由命名 ② 在復制組scott_mg里加入數(shù)據(jù)庫對象 SQLexecute dbms_repcat create_master_repobject(sname= scott oname= dept type= table use_existing_object=true gname= scott_mg ); 參數(shù)說明 sname 實現(xiàn)數(shù)據(jù)庫復制的用戶名稱 oname 實現(xiàn)數(shù)據(jù)庫復制的數(shù)據(jù)庫對象名稱 (表名長度在 個字節(jié)內 程序包名長度在 個字節(jié)內) type 實現(xiàn)數(shù)據(jù)庫復制的數(shù)據(jù)庫對象類別 (支持的類別 表 索引 同義詞 觸發(fā)器 視圖 過程 函數(shù) 程序包 程序包體) use_existing_object true表示用主復制節(jié)點已經存在的數(shù)據(jù)庫對象 gname 主復制組名 ③ 對數(shù)據(jù)庫對象產生復制支持 SQLexecute dbms_repcat generate_replication_support( scott dept table ); (說明 產生支持scott用戶下dept表復制的數(shù)據(jù)庫觸發(fā)器和程序包) ④ 確認復制的組和對象已經加入數(shù)據(jù)庫的數(shù)據(jù)字典 SQLselect gname master status from dba_repgroup; SQLselect * from dba_repobject; 創(chuàng)建主復制節(jié)點 ① 用repadmin身份登錄shenzhen數(shù)據(jù)庫 創(chuàng)建主復制節(jié)點 SQLexecute dbms_repcat add_master_database (gname= scott_mg master= use_existing_objects=true copy_rows=false propagation_mode = asynchronous ); 參數(shù)說明 gname 主復制組名 master 加入主復制節(jié)點的另一個數(shù)據(jù)庫 use_existing_object true表示用主復制節(jié)點已經存在的數(shù)據(jù)庫對象 copy_rows false表示第一次開始復制時不用和主復制節(jié)點保持一致 propagation_mode 異步地執(zhí)行 ② 確認復制的任務隊列已經加入數(shù)據(jù)庫的數(shù)據(jù)字典 SQLselect * from user_jobs; 使同步組的狀態(tài)由停頓(quiesced )改為正常(normal) ① 用repadmin身份登錄shenzhen數(shù)據(jù)庫 運行以下命令 SQL execute dbms_repcat resume_master_activity( scott_mg false); ② 確認同步組的狀態(tài)為正常(normal) SQL select gname master status from dba_repgroup; ③ 如果這個①命令不能使同步組的狀態(tài)為正常(normal) 可能有一些停頓的復制 運行以下 lishixinzhi/Article/program/Oracle/201311/16816
1、使用plsql連接上數(shù)據(jù)庫,展開【Tables】菜單項,下面出現(xiàn)的就是數(shù)據(jù)庫表。
2、在數(shù)據(jù)庫表tblTest上面點擊鼠標右鍵,選擇【Query data】,此項的目的是查詢這張數(shù)據(jù)庫表的數(shù)據(jù)。
3、點擊完成【Query data】之后,右側會出現(xiàn)一個SQL語句的窗口,默認有一條【select * from 表名】的sql語句,下方還有一個列表,展示這張表中的已有數(shù)據(jù)。
4、然后寫一條insert插入的SQL語句,寫完之后,選中這條SQL,點擊左上角的【次輪狀】圖標,然后,SQL語句下方會出現(xiàn)【1 row inserted in xx seconds】,表示語句執(zhí)行成功。此時數(shù)據(jù)還沒有真正寫入數(shù)據(jù)庫 insert插入sql格式:insert into 表名(字段1, 字段2, 字段n) values(值1, 值2, 值n)。
5、在Oracle數(shù)據(jù)庫中,對數(shù)據(jù)的變更還需要點擊【Commit】按鈕,也就是左上角向下箭頭的圖標,如果不點擊這個按鈕,數(shù)據(jù)其實不會真正存入數(shù)據(jù)庫。點擊【Commit】按鈕后,會彈出一個Confirm窗口,此時點擊【Yes】就將數(shù)據(jù)寫入數(shù)據(jù)庫,點擊【No】則不提交到數(shù)據(jù)庫。
你是要復制出來還是復制到另外一個表結構:
復制的話直接sql語句 :1. 復制表結構及其數(shù)據(jù): create table table_name_new as select * from table_name_old
2. 只復制表結構: create table table_name_new as select * from table_name_old where 1=2; 或者: create table table_name_new like table_name_old
3. 只復制表數(shù)據(jù):如果兩個表結構一樣:insert into table_name_new select * from table_name_old 如果兩個表結構不一樣:insert into table_name_new(column1,column2...) select column1,column2... from table_name_old
導出來的話指令不寫了、直接百度就有了。
標題名稱:oracle數(shù)據(jù)如何復制 oracle數(shù)據(jù)庫如何快速復制
URL網址:http://chinadenli.net/article8/hgpsop.html
成都網站建設公司_創(chuàng)新互聯(lián),為您提供網站收錄、電子商務、Google、定制開發(fā)、自適應網站、做網站
聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)