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 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?

Thank you,

1 Answer

You can cast() NULL to whatever type you want:

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

Note: Your code should work just as a SELECT. The issue comes if you are trying to save the data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

David Miller

David Miller

Executive Financial & Market Analyst

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.

Share this article
Twitter Facebook Pinterest