If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > common table expression

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-18-06, 06:28
krReddy krReddy is offline
Registered User
 
Join Date: Oct 2006
Posts: 83
Lightbulb common table expression

im curious to know what the below syntax does. Since this is a commomtable expression, which is new to me .

with mytable (temp ) as (values repeat('splendid',3))
select substr(temp || rtrim(coalesce(str,' ')),length(rtrim(coalesce(str,' ')))+1,len) from mytable
Reply With Quote
  #2 (permalink)  
Old 12-18-06, 06:42
Peter.Vanroose Peter.Vanroose is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
Quote:
Originally Posted by krReddy
im curious to know what the below syntax does. Since this is a commomtable expression, which is new to me .

with mytable (temp ) as (values repeat('splendid',3))
select substr(temp || rtrim(coalesce(str,' ')),length(rtrim(coalesce(str,' ')))+1,len) from mytable
A CTE can be seen as a (one-time) view. So the above is conceptually equivalent to:
Code:
CREATE VIEW mytable AS
SELECT 'splendidsplendidsplendid' AS temp FROM sysibm.sysdummy1 ;
select substr(temp || rtrim(coalesce(str,' ')),
              length(rtrim(coalesce(str,' ')))+1,
              len)
from   mytable
but without making the view visual in the catalog.

(This sould give an error at "str" and at "len", I believe.)
__________________
--_Peter Vanroose,
__IBM Certified Database Administrator, DB2 9 for z/OS
__IBM Certified Application Developer
__ABIS Training and Consulting
__http://www.abis.be/
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On