Reputation: 33
I have a database of SQL queries, procedures etc.
Now I have following SQL statement with concatenation operators.
'INSERT INTO TEST_TABLE(ID, NAME)' || 'SELECT ID, NAME FROM ' || ' MY_TABLE'
I want that when I get SQL back it return
INSERT INTO TEST_TABLE(ID, NAME) SELECT ID, NAME FROM MY_TABLE
This SQL is just for example but basically I want to remove concatenations and return simple SQL.
Thanks
Upvotes: 1
Views: 2689
Reputation: 9759
If i got the question right your looking for something like an eval
to make oracle evaluate the string with the concatenation marks.
Try something like this
declare
concatenetaed_sql varchar2(32000);
result_Sql varchar2(32000);
begin
concatenetaed_sql := '''INSERT INTO TEST_TABLE(ID, NAME)'' || ''SELECT ID, NAME FROM '' || '' MY_TABLE''';
execute immediate 'select ' || concatenetaed_sql || ' from dual'
into result_sql;
dbms_output.put_line(result_sql);
end;
And the result
INSERT INTO TEST_TABLE(ID, NAME)SELECT ID, NAME FROM MY_TABLE
PL/SQL procedure successfully completed.
Upvotes: 3