甜咖啡

          我的IT空間

          Oracle 把一個表中的數據插入到另外一個表中

          1.在Oracle中可以用下面兩種:

          01: 
               create table newtable   as select * from oldtable;//用于復制前未創建新表newtable不存在的情況 
          02: 
                insert into newtable   select * from oldtable;//已經創建了新表newtable 的情況

          注意:第一種方式只是復制了表結構,但是主鍵什么的并沒有復制進去,所以用的時候要小心在意。

          2.如果想簡單快速的復制表結構,而不需要oldtable里面的數據,可以用下面的語句:

              create table newtable   as  select * from oldtable where 1=2;(把數據過濾掉)

          3.如過newtable 和oldtable的表結構不同,可以使用下面的方式:

           create table newtable  as select  s.c1,s.c2  from oldtable s;

           

          4.如果想重新命名newtable的列名:

          在oracle中:

           create table  newtable(id,name1) as select  s.c1,s.c2  from oldtable s;

          或者

           create table  newtable as select  s.c1 ,s.c2  from oldtable s;

          在mysql中恐怕只能用第二種方式了。

          5.如果是只需要把一部分的oldtable中的數據添加到newtable中。可以這樣:

           create table newtable   as (select * from oldtable where ...);//加where過濾條件

          6.最常見的情況是id列新表中要用,并且和舊表中的不同,使用下面的語句就可以了(我們可以重新建一個sequence)

          create table yang(id,name) as select hibernate_sequence.nextval,t.ename from emp t;

          7.要注意,導出表的時候不能用select...into語句。

          posted on 2013-04-03 12:05 甜咖啡 閱讀(412) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          導航

          <2013年4月>
          31123456
          78910111213
          14151617181920
          21222324252627
          2829301234
          567891011

          統計

          常用鏈接

          留言簿(1)

          我參與的團隊

          隨筆檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 东乌珠穆沁旗| 霍林郭勒市| 钟祥市| 桂平市| 榆中县| 唐河县| 乌拉特中旗| 磴口县| 封开县| 克山县| 桃园县| 来安县| 扶风县| 辽中县| 濉溪县| 三明市| 福建省| 景谷| 霍林郭勒市| 东阳市| 枝江市| 南昌县| 福建省| 临猗县| 沁水县| 措美县| 湘潭县| 洛宁县| 柳州市| 怀安县| 泾源县| 武陟县| 新疆| 隆林| 汝阳县| 保山市| 棋牌| 林西县| 闽清县| 济宁市| 固安县|