dbTalk Databases Forums  

Select without from

comp.databases.ibm-db2 comp.databases.ibm-db2


Discuss Select without from in the comp.databases.ibm-db2 forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
M N
 
Posts: n/a

Default Select without from - 05-10-2011 , 02:14 PM






In many database systems you can perform a select without from, for
exapmle "SELECT 1" but DB2 doesn't allow this. In others like Oracle,
you can use dummy in-memory tables like "SELECT 1 FROM dual".

How can you do that in DB2?

Reply With Quote
  #2  
Old   
Lennart Jonsson
 
Posts: n/a

Default Re: Select without from - 05-10-2011 , 02:31 PM






On 2011-05-10 21:14, M N wrote:
Quote:
In many database systems you can perform a select without from, for
exapmle "SELECT 1" but DB2 doesn't allow this. In others like Oracle,
you can use dummy in-memory tables like "SELECT 1 FROM dual".

How can you do that in DB2?
values 1

or:

select 1 from sysibm.sysdummy1

or even:

select 1 from dual

but you will have to enable Oracle compability mode for that


/Lennart

Reply With Quote
  #3  
Old   
Frederik Engelen
 
Posts: n/a

Default Re: Select without from - 05-10-2011 , 04:24 PM



Quote:
select 1 from dual

but you will have to enable Oracle compability mode for that
Shoud you be on Express-C (no Oracle compatibility), you could do the
same by creating an alias called DUAL on the sysdummy1 view (not
tested though).

--
Frederik Engelen

Reply With Quote
  #4  
Old   
Serge Rielau
 
Posts: n/a

Default Re: Select without from - 05-11-2011 , 06:17 AM



BTW, VALUES 1 is actually ANSI SQL.
A mystery to me why no(?) other vendor supports VALUES in its full form
since it is very powerful



--
Serge Rielau
SQL Architect DB2 for LUW, IBM Toronto Lab
Blog: tinyurl.com/SQLTips4DB2
Wiki: tinyurl.com/Oracle2DB2Wiki
Twitter: srielau

Reply With Quote
  #5  
Old   
Lennart Jonsson
 
Posts: n/a

Default Re: Select without from - 05-11-2011 , 10:53 AM



On 2011-05-10 23:24, Frederik Engelen wrote:
Quote:
select 1 from dual

but you will have to enable Oracle compability mode for that

Shoud you be on Express-C (no Oracle compatibility), you could do the
same by creating an alias called DUAL on the sysdummy1 view (not
tested though).

It appears as if there already is an alias:

db2 "create public alias dual for sysibm.sysdummy1"
DB21034E The command was processed as an SQL statement because it was
not a
valid Command Line Processor command. During SQL processing it returned:
SQL0601N The name of the object to be created is identical to the existing
name "SYSPUBLIC.DUAL" of type "ALIAS". SQLSTATE=42710

I guess that db2set DB2_COMPATIBILITY_VECTOR=2 somehow makes this
accessible without having to qualify it with schema ( can't investigate
because I only have express on 9.7 )

/Lennart

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



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.