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 > Create table from hierarchy query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-16-09, 18:47
NMadson NMadson is offline
Registered User
 
Join Date: Apr 2009
Location: San Francisco
Posts: 4
Question Create table from hierarchy query

I'm trying to create a table from the results of a query of a recursive hieararchy.

At the end of the statement that builds the hieararchy in table TEMPTAB I say

CREATE TABLE MYDB.T_HIER
AS
(SELECT * from TEMPTAB);

I get an error message "An unexpected token 'MYDB' was found following 'CREATE TABLE'."

In Teradata I'd have to add "WITH DATA" after my select statement. I don't see that DB2 had or requires a similar statement.

How can I create a table from a query of a hierarchy?
Reply With Quote
  #2 (permalink)  
Old 04-17-09, 01:31
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
"WITH NO DATA" is mandatory in CREATE TABLE from full-select on DB2 for LUW.
Please see syntax diagram of CREATE TABLE in "DB2 Version 9.5 for LUW SQL Reference Volume 2"

So, you can't CREATE TABLE and populate data in it by one statement.

After CREATE TABLE, you can INSERT data in it from recursive query.
Like this:
INSERT INTO MYDB.T_HIER
WITH TEMPTAB(...) AS (.....) SELECT * FROM TEMPTAB;
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