===PL/SQL===
1.1
You can call another script from PL/SQL but it will be inlined in the code and must be correct PL/SQL snippet.
So if we modify original scripts
simple_sample1.sql
dbms_output.put_line(&1);
main.sql
begin
for loop_parameter in 1..3 loop
@simple_sample1.sql loop_parameter
end loop;
end;
/
Then result is following
SQL> @main
old 3: dbms_output.put_line(&1);
new 3: dbms_output.put_line(loop_parameter);
1
2
3
PL/SQL procedure successfully completed.
Of course, inlined code may look almost like standalone block if you wrap it with "begin" and "end".
begin
dbms_output.put_line(&1);
end;
1.2 If you want to run arbitrary script from PL/SQL you can run sqlplus from PL/SQL code using DBMS_SCHEDULER... but it's a bit weird, isn't it? I hope it's needless to say that script will be executed in another session created by DBMS_SCHEDULER.
===SQL===
2. You can inline code into SQL as well, but, again, query must compile after inlining.
hello.sql
'HELLO' || ' ' ||
SQL> select
2 @hello.sql
3 rownum
4 from dual
5 connect by rownum <= 3;
HELLO 1
HELLO 2
HELLO 3
SQL>
SQL> select
2 #START hello.sql
3 rownum
4 from dual
5 connect by rownum <= 3;
HELLO 1
HELLO 2
HELLO 3
===SPOOL===
3. Finally, you can generate in a loop what you need, spool it and execute it.
You can use either SQL or PL/SQL to generate the script. Example below shows SQL approach.
main_spool.sql
set echo off;
set pagesize 0;
spool tmp.sql
select
'@simple_sample.sql' || ' ' || rownum x
from dual
connect by rownum <= 3;
spool off
@tmp.sql
SQL> @main_spool
@simple_sample.sql 1
@simple_sample.sql 2
@simple_sample.sql 3
HELLO 1
HELLO 2
HELLO 3
PROMPTwill cause a syntax exception inexecute immedite.main.sql) and pass parameters to that SQL*Plus script.no way in sqlplus, then let it be. It was just interesting to find out if there's a possibility in sqlplus itself.