I'm using Oracle db and I wonder if it's possible to write something like:
INSERT INTO CL (select COLUMN_NAME from USER_TAB_COLUMNS where TABLE_NAME='CL')
SELECT * FROM CLT;
or:
INSERT INTO CL (select COLUMN_NAME from USER_TAB_COLUMNS where TABLE_NAME='CL')
SELECT (select COLUMN_NAME from USER_TAB_COLUMNS where TABLE_NAME='CL') FROM CLT;
So the idea is that both tables have the same columns, but the columns order don't match, so when I try to do simple
INSERT INTO CL
SELECT * FROM CLT;
I keep getting ORA-00932: inconsistent datatypes, it doesn't happen if I specify all columns one by one. But I don't want to do that, because my table has ~50 columns and I want to have robust solution that I could apply later to other tables as well.
That's why I was thinking about using subquery to get the column names in the INSERT INTO query but either this is not possible in sql or i'm doing something wrong.
Is there any way to skip order of the columns in that (and force sql to use the names maybe? ) or use subquery within that query to obtain two times all column names in the same order?
PS. I was thinking about reordering chaging them to INVISIBLE and back to VISIBLE but it's not supported in my version. Also it wouldn't be as reusable as I need.