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

Pau*_*Pau 6 sql oracle null

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

SELECT mytable. *, NULL as ColumnName
FROM mytable;
Run Code Online (Sandbox Code Playgroud)

错误代码是

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.
Run Code Online (Sandbox Code Playgroud)

所以看来不可能这样做。是否可以选择在 SELECT 语句中创建 NULL 列?

谢谢你,

Gor*_*off 10

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

SELECT t.*, CAST(NULL as VARCHAR2(100)) as ColumnName
FROM mytable t;
Run Code Online (Sandbox Code Playgroud)

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