【问题标题】:How I can create a table having two long columns?如何创建一个有两个长列的表?
【发布时间】:2012-07-23 16:07:20
【问题描述】:

我正在使用 Oracle 10 g。

我有一个需要Long 类型的两列的表:

CREATE TABLE emp
 (
    id1 LONG NULL,
    id2 LONG NULL,
    //
    // Other columns.
);

当我执行这个查询时,它给了我这个错误:

Error report:
SQL Error: ORA-01754: a table may contain only one column of type LONG
01754. 00000 -  "a table may contain only one column of type LONG"
*Cause:    An attempt was made to add a LONG column to a table which already
           had a LONG column. Note that even if the LONG column currently
           in the table has already been marked unused, another LONG column
           may not be added until the unused columns are dropped.
*Action:   Remove the LONG column currently in the table by using the ALTER
           TABLE command.

我在 Google 上进行了搜索,但找不到合适的解决方案。为什么他们不允许两列LONG

使用number 代替列是个好主意吗?

我怎样才能做到这一点?

【问题讨论】:

  • 如果您已经在修改 Quartz 表,您可能还想将 VARCHAR 更改为 VARCHAR2。他们的表格脚本有一些问题。

标签: sql oracle sqldatatypes


【解决方案1】:

LONG列好久不推荐了;从 8i 开始,我相信。来自the 11g documentation

不要创建包含 LONG 列的表。使用 LOB 列(CLOB、NCLOB、 BLOB) 代替。 LONG 列仅支持向后 兼容性。

您只能在一个表中使用一个 LONG 列。我不完全确定,但我认为这是因为LONG 数据与其他列一起存储,而且不止一个会使它更加难以管理。 LOB 的存储方式不同;请参阅表格here 进行比较。


Oracle 的LONG 数据类型是“可变长度的字符数据,最大为 2 GB”。如果您要存储数字数据,请使用NUMBER

如果您正在映射 Java 数据类型(根据您的个人资料猜测!),this table 可能有用。

【讨论】:

  • 这两种方法中哪一种最适合长期使用?以及如何从这个数据类型中取回长值?
  • @vikiiii - 也许这是一个完整的数据类型不匹配;您是否正在尝试查找与 C long 之类的数据类型匹配的数据类型?我从看起来像 ID 的列名猜测。 Oracle 的LONG 完全不同...
  • 是的。我的列是数字的。使用number 代替列是个好主意吗?或我可以使用的任何其他数据类型
【解决方案2】:

从 Oracle 8i 开始,建议不要使用 LONG 数据类型,而是使用 CLOB 或 NLOB 数据类型。

以防万一检查Oracle 10g documentation 关于数据类型。还有check here for other details

【讨论】:

    猜你喜欢
    • 2011-09-21
    • 2014-06-29
    • 1970-01-01
    • 1970-01-01
    • 2013-07-08
    • 1970-01-01
    • 1970-01-01
    • 2011-10-29
    • 1970-01-01
    相关资源
    最近更新 更多