【问题标题】:How to declare null column in SQL oracle in Select statement如何在 Select 语句中声明 SQL oracle 中的空列
【发布时间】:2018-06-05 03:04:33
【问题描述】:

我试图在 SELECT 语句中创建一个 NULL 列,但它不起作用:

SELECT mytable. *, NULL as ColumnName
FROM mytable;

错误代码是

Error report -
SQL Error: ORA-01723: zero-length columns are not allowed
01723. 00000 -  "zero-length columns are not allowed"
*Cause:    Columns with zero length were not allowed.
*Action:   Correct the use of the column.

所以似乎不可能做到这一点。有没有办法在SELECT语句中创建一个NULL列?

谢谢,

【问题讨论】:

    标签: sql oracle null


    【解决方案1】:

    您可以cast() NULL 为您想要的任何类型:

    SELECT t.*, CAST(NULL as VARCHAR2(100)) as ColumnName
    FROM mytable t;
    

    注意:您的代码应该像 SELECT 一样工作。如果您尝试保存数据,就会出现问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-20
      • 1970-01-01
      • 1970-01-01
      • 2017-09-06
      • 2015-10-30
      • 2014-03-27
      • 2013-08-03
      • 2015-01-16
      相关资源
      最近更新 更多