Oracle中資料表查詢拷貝

2021-09-01 16:20:44 字數 1843 閱讀 5861

[b] 一、oracle資料庫中,把一張表的查詢結果直接生成並匯入一張新錶中。[/b]

例如:現有只有a表,查詢a表,並且把結果匯入b表中。使用如下sql語句:

sql**

create table b as select * from a

[b]二、oracle資料庫中支援把查詢結果匯入到另外一張表中。[/b]

例如:有兩個表a和b

1)如果兩個表的表結構是否相同,但要插入的字段型別相同:

(1)把a表的全部字段資料插入到b表中:

sql**

insert into b select * from a;

(2)把a表中某些欄位的資料插入b表中:

sql**

insert into b(欄位名)(select 欄位名 from a)

2)如果不在同乙個schema下在表名前加上schema,例如有schema x和y:

sql**

insert into y.b select * from x.a

[b]三、一些非常有用的oracle sql( 前提,要開啟windows command line視窗)[/b]

1。開啟sqlplus

c> sqlplus /nolog

2。連線到指定資料庫 www.2cto.com

sql>connect user/password@sid 或者

sql>connect user/password@localhost(ip address):1521/sid

3。查詢該schema下的所有使用者表

sql>select table_name from user_tables;

4。使用dba身份登陸資料庫

sql>connect system/manager@sid as sysdba;

5。系統表中檢索使用者

sql>select name, password from sys.user$ where name = ''zhangsan';

6。修改使用者密碼

sql>alter user user_name identified by new_password;

7。查詢dba profile表

sql>select * from dba_profiles where profile='default_profile';

8。使用完整模式匯出指定資料庫

sql>exp 'system/manager@sid as sysdba' full=y file=c:\dbfulldata.dmp log=c:\dbfulldata.log

9。匯入到新的資料庫中

sql>imp system/manager@sid full=y ignore=y file==imp_dbfull.dmp log=imp_dbfull.dmp.log

10。輸出sql執行結果到指定的檔案

sql>spool c:\result.txt;

sql>select * from yourtables;

sql>spool off; --強制清孔緩衝區資料到指定txt檔案

11。修改system使用者的密碼

sql>connect sys/install_on_change@sid as sysdba;

sql>alter user system identified by new_password;

12。檢視oracle當前版本資訊

sql>select * from v$version;

13。刪除資料庫sid

c\:>oradim -delete -sid sid

14。檢視使用者資訊

sql>select * from dba_users;

資料表的拷貝

兩張表進行資料的拷貝,最常用的拷貝語句是 insert into select 和 select into from 但是請絕對的注意 在oracle中select into from不可以使用 原因很簡單 select into是pl sql language 的賦值語句!如果使用則oracle會...

oracle的查詢資料表(五)

判斷null值 當要檢查列中是否包含空值的時候,需要使用is null 或者is not null語句,null通常為空值,空值的意思就是未指定的,不存在的值,不能與空白值相混淆,空白值是乙個村莊的,只是值為空白的值,使用邏輯組合在where子句中除了使用單個布林表示式外,還可以通過使用邏輯條件組合...

oracle的查詢資料表(五)

排序 通過在查詢結果中應用排序,可以使得查詢的結果順序按照指定的順序進行排序,在select子句中可以使用order by子句排序,可以為order by子句指定乙個表示式或乙個列名作為排序的條件 注意 order by 子句必須是select語句的最後乙個子句,否則select語句將會執行失敗 s...