6

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 1

11

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.