var sidebar_align = 'right';
var content_container_margin = parseInt('290px');
var sidebar_width = parseInt('270px');
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
(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?
"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.
INSERT INTO MYDB.T_HIER
WITH TEMPTAB(...) AS (.....) SELECT * FROM TEMPTAB;