oracle 動作表

來源:互聯網
上載者:User

標籤:

1、不同使用者之間的表資料複製

2、同使用者表之間的資料複製

3、B.x中個別欄位轉移到B.y的相同欄位

4、只複製表結構 加入了一個永遠不可能成立的條件1=2,則此時表示的是只複製表結構,但是不複製表內容

5、完全複製表(包括建立表和複製表中的記錄) 

6、將多個表資料插入一個表中

7、建立使用者budget_zlgc,許可權和budget相同,(A、只複製所有表結構B、複製所有表所有資訊)

 

1.不同使用者之間的表資料複製  對於在一個資料庫上的兩個使用者A和B,假如需要把A下表old的資料複製到B下的new,請使用許可權足夠的使用者登入sqlplus: insert into B.new(select * from A.old);

如果需要加條件限制,比如複製當天的A.old資料 insert into B.new(select * from A.old where date=GMT);  藍色斜線處為選擇條件

2.同使用者表之間的資料複製  使用者B下有兩個表:B.x和B.y,如果需要從表x轉移資料到表y,使用使用者B登陸sqlpus即可: insert into 目標表y select * from x where log_id>‘3049‘ -- 複製資料  注意:要示目標表y必須事先建立好 如insert into bs_log2 select * from bs_log where log_id>‘3049‘    

3.B.x中個別欄位轉移到B.y的相同欄位  --如果兩個表結構一樣 insert into table_name_new select * from table_name_old  如果兩個表結構不一樣: insert into y(欄位1,欄位2) select 欄位1,欄位2 from x

4.只複製表結構 加入了一個永遠不可能成立的條件1=2,則此時表示的是只複製表結構,但是不複製表內容    create table 使用者名稱.表名 as select * from 使用者名稱.表名 where 1=2 如create table zdsy.bs_log2 as select * from zdsy.bs_log where 1=2

5完全複製表(包括建立表和複製表中的記錄) create table test as select * from bs_log  --bs_log是被複製表

將多個表資料插入一個表中 insert into 目標表test(欄位1。。。欄位n) (select 欄位1.。。。。欄位n) from 表 union all select 欄位1.....欄位n from 表

 

7、建立使用者budget_zlgc,許可權和budget相同,A、只複製所有表結構

B、複製所有表所有資訊)

建立使用者budget_zlgc,並匯出budge使用者資料

exp userid="\"sys/sys as sysdba"\" file=‘/backup/expdb/oa0824.dmp‘ log=‘/backup/expdb/oaex0825.log‘ owner=budget ignore=Y buffer=256000000

 

Abudget使用者所有表,表結構和budget相同,(無資料)

imp userid="\"sys/sys as sysdba"\" file=‘/backup/expdb/oa0824.dmp‘ log=‘/backup/expdb/oa0825.log‘ fromuser=budget touser=budget_zlgc ignore=Y buffer=256000000 rows=n

Bbudget使用者所有表,表結構、資料和budget相同

imp userid="\"sys/sys as sysdba"\" file=‘/backup/expdb/oa0824.dmp‘ log=‘/backup/expdb/oa0825.log‘ fromuser=budget touser=budget_zlgc ignore=Y

 

 

 

 

===================================================== oracle和mssql中複製表的比較

庫內資料複製 MS SQL Server:  Insert into 複製表名稱 select 語句 (複製表已經存在) select 欄位列表 into 複製表名稱 from 表 (複製表不存在)

Oracle : Insert into 複製表名稱 select 語句 (複製表已經存在) create table 複製表名稱 as select 語句 (複製表不存在)

多表更新、刪除

一條更新語句是不能更新多張表的,除非使用觸發器隱含更新,我這裡說的意思是:根據其他表資料更新你要更新的表一般形式: MS SQL Server  update ASET 欄位1=B表欄位運算式,欄位2=B表欄位運算式from BWHERE 邏輯運算式

Oracle  update ASET 欄位1=(select 欄位運算式 from B WHERE ...),欄位2=(select 欄位運算式 from B WHERE ...) WHERE 邏輯運算式 從以上來看,感覺oracle沒有ms sql好,主要原因:假如A需要多個欄位更新,MS_SQL 語句更簡練你知道剛學資料庫的人怎麼做上面這件事情

嗎,他們使用遊標一條一條的處理

====匯入==匯出=========== (1)匯出 exp ff/[email protected] file=‘d:ff.dmp‘ tables=customers direct=y 使用exp 輸出。輸入的為需要備份的使用者表的帳號和密碼,根據提示一直點斷行符號就OK 結束後將會出現一個ff.DMP檔案,此檔案為備份資料。 匯出時可以選擇匯出:1.整個資料庫(需具備dba許可權);2.使用者(包括表、視圖和其它);3.表(只包含表,不匯出視圖);

(2)匯入 create user ly identified by pw default tablespace users quota 10M on users;  建立新使用者 使用者名稱為ly 密碼為pw 預設資料表空間為此空間,配額為10M grant connect,resource,dba to ly; 賦予ly許可權(1.串連;2.資源;3.dba許可權,必須具備才能執行匯入!) grant create session,create table,create view,unlimited tablespaces to ly;  賦予ly其它常用許可權(1.登陸到伺服器,2.建立表,3.建立視圖,4.無限資料表空間) imp ly/[email protected] fromuser=ff touser=ly file=‘d:ff.dmp‘ constraints=n 使用 imp 輸入。輸入需要匯入的使用者的使用者名稱和密碼 然後點斷行符號,根據提示一直到再次要求你輸入使用者名稱的地方。

=================

sql_server不同資料庫間複製表
不同資料庫表結構 和資料的複製 :  目標資料庫不存在要匯入的表時:  example:  xuexiao為目標資料庫,teaching為來源資料庫,dbo.course_list已經存在於teaching,想在沒有此表的xuexiao庫中複製一個用下面的陳述式完成

:  select * into xuexiao.dbo.course_list from teaching.dbo.course_list 
不同資料庫之間複製表的資料的方法

當表目標表存在時:  insert into 目的資料庫..表 select * from 來源資料庫..表

當目標表不存在時:  select * into 目的資料庫..表 from 來源資料庫..表  ================================================= 如下,表a是資料庫中已經存在的表,b是準備根據表a進行複製建立的表:

  1、只複製表結構的sql   create table b as select * from a where 1<>1

  2、即複製表結構又複製表中資料的sql   create table b as select * from a

  3、複製表的制定欄位的sql   create table b as select row_id,name,age from a where 1<>1//前提是row_id,name,age都是a表的列

  4、複製表的指定欄位及這些指定欄位的資料的sql   create table b as select row_id,name,age from a

  以上語句雖然能夠很容易的根據a表結構複製建立b表,但是a表的索引等卻複製不了,需要在b中手動建立。

  5、insert into 會將查詢結果儲存到已經存在的表中   insert into t2(column1, column2, ....) select column1, column2, .... from t1

 

 

1、獲得單個表和索引DDL語句的方法: 
----------------------------------------------------------------------- 
set   heading   off; 
set   echo   off; 
Set   pages   999; 
set   long   90000; 
  
spool   get_single.sql 
select   dbms_metadata.get_ddl( ‘TABLE ‘, ‘SZT_PQSO2 ‘, ‘SHQSYS ‘)   from   dual; 
select   dbms_metadata.get_ddl( ‘INDEX ‘, ‘INDXX_PQZJYW ‘, ‘SHQSYS ‘)   from   dual;
spool   off;

 

uffer=256000000

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.