This is a discussion on Select null as xyz from sysibm.sysdummy1 within the DB2 forums, part of the Database Server Software category; --> Hi, Why is it that this command doesn't work in DB2. I have to create a view in which ...
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Hi, Why is it that this command doesn't work in DB2. I have to create a view in which one of the columns has to be null(Don't ask me why that should always be null, because the view in Oracle and DB2 should have same columns and Oracle view has col as null) So i try ... Create view......null as col....... It fails in DB2, but works in Oracle. Please tell what should be done to set the field as null. Thanks a lot Rahul |
| |||
| Try something along the lines of: CAST(NULL as CHAR) CAST(NULL AS DATE) CAST(NULL as INTEGER) hth aj Rahul B wrote: > Hi, > > Why is it that this command doesn't work in DB2. > I have to create a view in which one of the columns has to be > null(Don't ask me why that should always be null, because the view in > Oracle and DB2 should have same columns and Oracle view has col as > null) > So i try ... > Create view......null as col....... > > It fails in DB2, but works in Oracle. > > Please tell what should be done to set the field as null. > > Thanks a lot > > Rahul > |
| |||
| On Thu, 16 Aug 2007 12:25:06 -0000, Rahul B <rahul.babbar1@gmail.com> wrote: >Hi, > >Why is it that this command doesn't work in DB2. >I have to create a view in which one of the columns has to be >null(Don't ask me why that should always be null, because the view in >Oracle and DB2 should have same columns and Oracle view has col as >null) >So i try ... >Create view......null as col....... > >It fails in DB2, but works in Oracle. > >Please tell what should be done to set the field as null. > >Thanks a lot > >Rahul CAST the NULL. Or, being it has to match Oracle, and Oracle uses a zero-length string for NULL, just use ''. B. |
| |||
| Rahul B wrote: > It fails in DB2, but works in Oracle. What's the type of such a NULL in Oracle? If I do: CREATE TABLE T(c1) AS (SELECT NULL FROM DUAL) What is c1? Cheers Serge -- Serge Rielau DB2 Solutions Development IBM Toronto Lab |
| |||
| On Aug 16, 7:04 pm, Serge Rielau <srie...@ca.ibm.com> wrote: > Rahul B wrote: > > It fails in DB2, but works in Oracle. > > What's the type of such a NULL in Oracle? > If I do: > CREATE TABLE T(c1) AS (SELECT NULL FROM DUAL) > > What is c1? > > Cheers > Serge > > -- > Serge Rielau > DB2 Solutions Development > IBM Toronto Lab Hi, It seems we cannot create a table in Oracle with null as a column but only a view or a simple select statement like select null as xyz from dual; It gives the error saying zero length columns are not allowed. Rahul |
| ||||
| Rahul B wrote: > It gives the error saying zero length columns are not allowed. Seems like they default to a CHAR(0).... Anyway, to make a long story short DB2's unwillingness to type NULL more aggressively is rooted in the strong typing. NULls are allowed for: 1. Input to CAST (obviously) 2. Input to stored procs (because there is no overloading by type) 3. Right hand side of SET clause (since the column/variable type is known) 4. INSERT VALUES clause (again casting to the column) Cheers Serge -- Serge Rielau DB2 Solutions Development IBM Toronto Lab |