I am using a few temp tables in Oracle to store some data, which is needed later in the function. To determine the data I need to store in the table, I am using a dynamic sql statement (using parameters as column names of other tables). I tried to different approaches.
The first time, I tried something like this:
INSERT INTO temp_tableA
EXECUTE IMMEDIATE dynamic_sql
USING IN OUT temp_tableB
And the other approach was like:
EXECUTE IMMEDIATE INTO temp_tableA
USING IN OUT temp_tableB
I already used some other temp table (temp_tableB) to store some data it seems, that it worked fine with the first approach, but there I did not have to use a dynamic sql statement. If I am trying to do it the same way with dynamic sql (so like the first approach) it tells me, that the keyword VALUES is missing. The second try returns the error message, that temp_tableA can't be used as an INTO-target of a SELECT/FETCH-Statement.
What am I missing? I have to say, that I am quite new to Oracle and it's starting to drive me crazy :D
insert into temp_tableA (...) select ... from temp_tableB ... where ...- i.e. no need for dynamic sql at all. But that's just a guess, hence the need for more info.v_sql := insert into some_table (col1, col2, col3) select '||p_col1||', '||p_col2||', '||p_col3||' from temp_tableA ta inner join temp_tableB tb on ta.col1 = tb.col1 where '||p_col4||' = '||p_col4_val;?