Try this:
declare
text varchar2(4000);
begin
select code into text from bkp_table;
execute immediate 'create or replace ' || text;
end;
/
Ok this works if all lines of code are stored in single line. If you want to execute code that is stored in multiple lines you should go for something like:
declare
text varchar2(32767);
begin
select listagg(text, ' ') within group (order by line) into text from all_source where name = 'MYPROC';
execute immediate 'create or replace ' || text;
end;
/
Problem starts when 32767 characters is too few. In such case this may be a solution:
declare
text clob;
begin
for x in (select text from all_source where name = 'LONGTEST') loop
text := text || x.text;
end loop;
execute immediate 'create or replace ' || text;
end;
/
Please also have a look on that why it is a bit odd thing.
EDIT
As suggested changed to dbms_lob and in that case clob needs to be initialised:
declare
text clob := ' ';
begin
for x in (select text from all_source where name = 'LONGTEST') loop
dbms_lob.append(text, x.text);
end loop;
execute immediate 'create or replace ' || text;
end;
/
dbms_sqlor/andexecute immediate