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