Is there a way to return a blank string for a field in SQL, even if the field has data?
SELECT NAME, AGE, DOB, GENDER, CITY
FROM TABLE
I want DOB, to always return blank ''
Is there a way to return a blank string for a field in SQL, even if the field has data?
SELECT NAME, AGE, DOB, GENDER, CITY
FROM TABLE
I want DOB, to always return blank ''
In Oracle, an empty VARCHAR2 is equivalent to a NULL
value.
So you can just do:
SELECT NAME,
AGE,
NULL AS DOB,
GENDER,
CITY
FROM TABLE
If you want to give it a specific data type then you can use CAST
:
SELECT NAME,
AGE,
CAST( NULL AS DATE ) AS DOB,
GENDER,
CITY
FROM TABLE
try this:
SELECT NAME, AGE, ' ' as DOB, GENDER, CITY
FROM TABLE
You could use NVL2
:
SELECT NVL2(dob, '', NULL) --rest of cols
FROM TABLE;
Please note that ''
is the same as NULL
. So you have:
SELECT '' AS DOB -- rest of cols
FROM TABLE;