Unix Technical Forum

Select null as xyz from sysibm.sysdummy1

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


Go Back   Unix Technical Forum > Database Server Software > DB2

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-27-2008, 01:04 PM
Rahul B
 
Posts: n/a
Default Select null as xyz from sysibm.sysdummy1

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-27-2008, 01:04 PM
aj
 
Posts: n/a
Default Re: Select null as xyz from sysibm.sysdummy1

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
>

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-27-2008, 01:04 PM
Brian Tkatch
 
Posts: n/a
Default Re: Select null as xyz from sysibm.sysdummy1

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-27-2008, 01:04 PM
Serge Rielau
 
Posts: n/a
Default Re: Select null as xyz from sysibm.sysdummy1

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-27-2008, 01:04 PM
Rahul B
 
Posts: n/a
Default Re: Select null as xyz from sysibm.sysdummy1

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-27-2008, 01:04 PM
Serge Rielau
 
Posts: n/a
Default Re: Select null as xyz from sysibm.sysdummy1

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 06:42 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com