AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / dba / 问题 / 10893
Accepted
kupa
kupa
Asked: 2012-01-19 08:40:14 +0800 CST2012-01-19 08:40:14 +0800 CST 2012-01-19 08:40:14 +0800 CST

Oracle:逐行读取CLOB列并插入到表中

  • 772

我有 CLOB 列,并想逐行读取其数据以将其插入另一个表中。

现在让我们创建与我相同的情况:

表MyTable_1中的数据

OWNER | TABLE_NAME | SQL
----------------------------
HR    | AAA        | <CLOB>

里面有<CLOB>以下数据:

CREATE TABLE AAA
( A NUMBER
);

我希望我的桌子看起来像这样(我们称之为MyTable_2):

OWNER | TABLE_NAME | SQL
----------------------------
HR    | AAA        |CREATE TABLE AAA
HR    | AAA        |( A NUMBER
HR    | AAA        |);
oracle
  • 1 1 个回答
  • 8179 Views

1 个回答

  • Voted
  1. Best Answer
    Jack Douglas
    2012-01-19T09:59:01+08:002012-01-19T09:59:01+08:00

    这不是一个完整的答案,因为它仅在您clob少于 4000 个字符时才有效。Clob 版本(在查询中使用普通版本bar而不是to_char(bar)在查询中)失败ORA-00932: inconsistent datatypes: expected - got CLOB- 也许其他人可以准确解释原因?

    试验台:

    drop table foo;
    create table foo(id integer, bar clob);
    insert into foo(id, bar) values (1, 'Hello'||chr(10)||'there');
    insert into foo(id, bar) values (2, 'Hello'||chr(10)||'there'||chr(10)||'again');
    

    询问:

    with w(id, line#, line, rest) as (
      select id, 1, regexp_substr(to_char(bar), '^.*?$', 1, 1, 'm'), 
             substr(to_char(bar), regexp_instr(bar, '$', 1, 1, 1, 'm')+1)
      from foo
      union all
      select id, line#+1, regexp_substr(rest, '^.*?$', 1, 1, 'm'), 
             substr(rest, regexp_instr(rest, '$', 1, 1, 1, 'm')+1)
      from w
      where rest is not null ) cycle id, line# set is_cycle to '1' default '0'
    select id, line#, line from w order by id, line#;
    /*
    ID                     LINE#                  LINE                                     
    ---------------------- ---------------------- ---------------------------------------- 
    1                      1                      Hello                                    
    1                      2                      there                                    
    2                      1                      Hello                                    
    2                      2                      there                                    
    2                      3                      again                                    
    */
    
    • 2

相关问题

  • Oracle 中的数据库备份 - 导出数据库还是使用其他工具?

  • ORDER BY 使用文本列的自定义优先级

  • 舒服的sqlplus界面?[关闭]

  • 如何在数据库中找到最新的 SQL 语句?

  • 如何使用正则表达式查询名称?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何查看 Oracle 中的数据库列表?

    • 8 个回答
  • Marko Smith

    mysql innodb_buffer_pool_size 应该有多大?

    • 4 个回答
  • Marko Smith

    列出指定表的所有列

    • 5 个回答
  • Marko Smith

    从 .frm 和 .ibd 文件恢复表?

    • 10 个回答
  • Marko Smith

    如何在不修改我自己的 tnsnames.ora 的情况下使用 sqlplus 连接到位于另一台主机上的 Oracle 数据库

    • 4 个回答
  • Marko Smith

    你如何mysqldump特定的表?

    • 4 个回答
  • Marko Smith

    如何选择每组的第一行?

    • 6 个回答
  • Marko Smith

    使用 psql 列出数据库权限

    • 10 个回答
  • Marko Smith

    如何从 PostgreSQL 中的选择查询中将值插入表中?

    • 4 个回答
  • Marko Smith

    如何使用 psql 列出所有数据库和表?

    • 7 个回答
  • Martin Hope
    Mike Walsh 为什么事务日志不断增长或空间不足? 2012-12-05 18:11:22 +0800 CST
  • Martin Hope
    Stephane Rolland 列出指定表的所有列 2012-08-14 04:44:44 +0800 CST
  • Martin Hope
    haxney MySQL 能否合理地对数十亿行执行查询? 2012-07-03 11:36:13 +0800 CST
  • Martin Hope
    qazwsx 如何监控大型 .sql 文件的导入进度? 2012-05-03 08:54:41 +0800 CST
  • Martin Hope
    markdorison 你如何mysqldump特定的表? 2011-12-17 12:39:37 +0800 CST
  • Martin Hope
    pedrosanta 使用 psql 列出数据库权限 2011-08-04 11:01:21 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 对 SQL 查询进行计时? 2011-06-04 02:22:54 +0800 CST
  • Martin Hope
    Jonas 如何从 PostgreSQL 中的选择查询中将值插入表中? 2011-05-28 00:33:05 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 列出所有数据库和表? 2011-02-18 00:45:49 +0800 CST
  • Martin Hope
    bernd_k 什么时候应该使用唯一约束而不是唯一索引? 2011-01-05 02:32:27 +0800 CST

热门标签

sql-server mysql postgresql sql-server-2014 sql-server-2016 oracle sql-server-2008 database-design query-performance sql-server-2017

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve