Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2009
    Location
    San Francisco
    Posts
    4

    Question Unanswered: 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?

  2. #2
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,483
    "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;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •