简体   繁体   English

如何在Select语句中的SQL oracle中声明空列

[英]How to declare null column in SQL oracle in Select statement

I'm trying to create a NULL column in the SELECT statement but it doesn't work: 我正在尝试在SELECT语句中创建NULL列,但它不起作用:

SELECT mytable. *, NULL as ColumnName
FROM mytable;

The error code is 错误代码是

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.

So it seems like it's not possible to do that. 因此,似乎不可能做到这一点。 Is there any choice to create a NULL column in the SELECT statement? 是否可以在SELECT语句中创建NULL列?

Thank you, 谢谢,

You can cast() NULL to whatever type you want: 您可以cast() NULL为所需的任何类型:

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

Note: Your code should work just as a SELECT . 注意:您的代码应像SELECT一样工作。 The issue comes if you are trying to save the data. 如果您要保存数据,则会出现问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM