Generate create table DDL from any arbitrary select query?
One way to accomplish this, using Java, would be to prepare the query statement, then use the PreparedStatement.getMetaData() method to obtain the ResultSetMetaData object that has the list of columns that would be returned, as well as their data types.

Other database interfaces, such as ODBC and OCI, have similar functionality.