查看: 10228|回复: 15

请问有long类型的表如何复制?

[复制链接]
招聘 : 数据库管理员
论坛徽章:
38
ITPUB北京九华山庄2008年会纪念徽章
日期:2008-01-21 16:50:24马上有对象
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有车
日期:2014-02-19 11:55:14现任管理团队成员
日期:2012-10-18 17:11:21版主4段
日期:2012-05-15 15:24:112012新春纪念徽章
日期:2012-02-13 15:09:232012新春纪念徽章
日期:2012-02-13 15:09:232012新春纪念徽章
日期:2012-02-13 15:09:23
跳转到指定楼层
1#
发表于 2004-12-24 11:29 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
表t中有一个字段类型是long并且不可能更改,现在我要复制这个表,我用create table newtab as select * from t会报错,这样的表该如何用SQL复制呢?
论坛徽章:
92
2011新春纪念徽章
日期:2011-01-25 15:42:33咸鸭蛋
日期:2012-03-19 10:46:00版主1段
日期:2012-05-15 15:24:11奥运会纪念徽章:排球
日期:2012-08-29 07:02:50奥运会纪念徽章:跳水
日期:2012-09-26 06:44:27ITPUB 11周年纪念徽章
日期:2012-09-28 17:34:42ITPUB 11周年纪念徽章
日期:2012-10-09 18:03:32奥运会纪念徽章:击剑
日期:2012-10-12 07:20:332013年新春福章
日期:2013-02-25 14:51:242012新春纪念徽章
日期:2012-02-13 15:13:20
2#
发表于 2004-12-24 13:59 | 只看该作者
Connected to:
Oracle8i Enterprise Edition Release 8.1.7.0.0 - Production
With the Partitioning option
JServer Release 8.1.7.0.0 - Production

SQL> create table testlong(text long);

Table created.

SQL> insert into testlong values('create table as select ');

1 row created.

SQL> insert into testlong select * from testlong;
insert into testlong select * from testlong
                            *
ERROR at line 1:
ORA-00997: illegal use of LONG datatype


SQL> commit;

Commit complete.

SQL> declare
  2  tempv long;
  3  begin
  4  select text into tempv from testlong where rownum=1;
  5  insert into testlong values(tempv);
  6  end;
  7  /

PL/SQL procedure successfully completed.

SQL> select * from testlong;

TEXT
--------------------------------------------------------------------------------

create table as select
create table as select

SQL>

使用道具 举报

回复
招聘 : 数据库管理员
论坛徽章:
38
ITPUB北京九华山庄2008年会纪念徽章
日期:2008-01-21 16:50:24马上有对象
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有车
日期:2014-02-19 11:55:14现任管理团队成员
日期:2012-10-18 17:11:21版主4段
日期:2012-05-15 15:24:112012新春纪念徽章
日期:2012-02-13 15:09:232012新春纪念徽章
日期:2012-02-13 15:09:232012新春纪念徽章
日期:2012-02-13 15:09:23
3#
 楼主| 发表于 2004-12-24 15:44 | 只看该作者
谢谢版主了,但是如果不用PL/SQL块而只用SQL能实现么?

使用道具 举报

回复
论坛徽章:
2
授权会员
日期:2005-10-30 17:05:33会员2006贡献徽章
日期:2006-04-17 13:46:34
4#
发表于 2004-12-24 16:29 | 只看该作者
sqlplus 的copy命令

使用道具 举报

回复
论坛徽章:
92
2011新春纪念徽章
日期:2011-01-25 15:42:33咸鸭蛋
日期:2012-03-19 10:46:00版主1段
日期:2012-05-15 15:24:11奥运会纪念徽章:排球
日期:2012-08-29 07:02:50奥运会纪念徽章:跳水
日期:2012-09-26 06:44:27ITPUB 11周年纪念徽章
日期:2012-09-28 17:34:42ITPUB 11周年纪念徽章
日期:2012-10-09 18:03:32奥运会纪念徽章:击剑
日期:2012-10-12 07:20:332013年新春福章
日期:2013-02-25 14:51:242012新春纪念徽章
日期:2012-02-13 15:13:20
5#
发表于 2004-12-26 18:27 | 只看该作者
最初由 l2g32003 发布
[B]sqlplus 的copy命令 [/B]

good
l2g32003的好东东真多阿

http://asktom.oracle.com/~tkyte/Misc/MoveLongs.html

Moving LONGS Around
The question "How do I move a LONG column from one table to another" comes up from time to time.  The following shows how to use SQLPlus to copy longs from table to table or database to database.  Note that this does not work for long raws.  There simply are no good solutions for long raws without coding C.
The sql*plus copy command will do it for longs.  You need a sql*net connect string that loops back to your local database (not a dblink, a sqlplus connect string, you need to be able to "sqlplus scott/tiger@yourdatabase"...
  
For example, I just:
  

create table foo
( The_Whole_View   varchar2(65),
  TextLength       number,
  TheText          Long )
/
  
which is a table, sort of like all_views (which has a long)...  Then I:
  
SQL> copy from tkyte/tkyte@aria insert foo (the_whole_view, textlength, thetext ) using select owner||'.'||view_name, text_length, text from all_views;
  
So the sqlplus command transformed the table for me (the columns are not the
same).  Also, I could have used a where clause to pick off just some rows.
You'll want to set

set arraysize N -- amount of rows the copy command will copy with each fetch
set long N -- size of your longest long
set copycommit M -- number of fetches to do before commit (N*M rows!!)
  
in plus before doing this.  see the manual for all the options....

使用道具 举报

回复
招聘 : 数据库管理员
论坛徽章:
38
ITPUB北京九华山庄2008年会纪念徽章
日期:2008-01-21 16:50:24马上有对象
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有车
日期:2014-02-19 11:55:14现任管理团队成员
日期:2012-10-18 17:11:21版主4段
日期:2012-05-15 15:24:112012新春纪念徽章
日期:2012-02-13 15:09:232012新春纪念徽章
日期:2012-02-13 15:09:232012新春纪念徽章
日期:2012-02-13 15:09:23
6#
 楼主| 发表于 2004-12-27 10:38 | 只看该作者
谢谢了,根据玉面飞“猫”老兄的指引,我做了如下试验:
SQL> CONN / AS SYSDBA

SQL> create table foo
  2  ( The_Whole_View   varchar2(65),
  3    TextLength       number,
  4    TheText          Long );

Table created.

SQL> copy help  --此为copy命令的帮助信息
usage: COPY FROM <db> TO <db> <opt> <table> { (<cols> } USING <sel>
  <db>   : database string, e.g., hr/your_password@d:chicago-mktg
  <opt>  : ONE of the keywords: APPEND, CREATE, INSERT or REPLACE
  <table>: name of the destination table
  <cols> : a comma-separated list of destination column aliases
  <sel>  : any valid SQL SELECT statement
A missing FROM or TO clause uses the current SQL*Plus connection.

SQL> copy from system/***@orcl insert foo(the_whole_view, textlength, thetext ) using select owne
r||'.'||view_name, text_length, text from all_views;

Array fetch/bind size is 15. (arraysize is 15)
Will commit when done. (copycommit is 0)
Maximum long size is 80. (long is 80)
   3522 rows selected from system@orcl.
   3522 rows inserted into FOO.
   3522 rows committed into FOO at DEFAULT HOST connection.

SQL> select count(*) from foo;

  COUNT(*)
----------
      3522
--一些copy命令的相关参数
set arraysize N -- amount of rows the copy command will copy with each fetch
set long N -- size of your longest long
set copycommit M -- number of fetches to do before commit (N*M rows!!)

使用道具 举报

回复
论坛徽章:
31
授权会员
日期:2005-10-30 17:05:332012新春纪念徽章
日期:2012-02-13 15:09:232012新春纪念徽章
日期:2012-02-13 15:09:232012新春纪念徽章
日期:2012-02-13 15:09:232012新春纪念徽章
日期:2012-02-13 15:09:23马上有车
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:142012新春纪念徽章
日期:2012-02-13 15:09:23
7#
发表于 2004-12-27 10:52 | 只看该作者
好贴
保留先!

使用道具 举报

回复
招聘 : 数据库管理员
论坛徽章:
38
ITPUB北京九华山庄2008年会纪念徽章
日期:2008-01-21 16:50:24马上有对象
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有车
日期:2014-02-19 11:55:14现任管理团队成员
日期:2012-10-18 17:11:21版主4段
日期:2012-05-15 15:24:112012新春纪念徽章
日期:2012-02-13 15:09:232012新春纪念徽章
日期:2012-02-13 15:09:232012新春纪念徽章
日期:2012-02-13 15:09:23
8#
 楼主| 发表于 2004-12-27 11:50 | 只看该作者
哦,再问一下,各位高手,如何取得long类型字段的前50个字符呢?应该有个函数的吧。

使用道具 举报

回复
论坛徽章:
7
ITPUB元老
日期:2005-04-22 09:33:06授权会员
日期:2005-10-30 17:05:33铁扇公主
日期:2006-04-13 11:04:44紫蜘蛛
日期:2006-04-13 11:05:58会员2006贡献徽章
日期:2006-04-17 13:46:34BLOG每日发帖之星
日期:2009-05-24 01:01:022010新春纪念徽章
日期:2010-03-01 11:08:29
9#
发表于 2005-3-22 10:03 | 只看该作者
好像没有直接的函数,可以先转换成clob再用dbms_lob.substr来取

使用道具 举报

回复
论坛徽章:
0
10#
发表于 2006-1-11 21:42 | 只看该作者
好贴!

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表