I have search this forum and via google for an answer for my question, but I can't find a specific answer for my challenge. That is why I am asking it here to hope to receive an answer from one of you guys.
I want to work with multiple SQL files, whereas one SQL file is the control file that executes the other SQL files with parameters. That file is called: startup.sql
I have a table with all my values (don't mind the names of the columns, I changed them for my post).
create table control (
S varchar2(15) not null,
N varchar2(25 char) not null,
B varchar2(25 char) not null,
Acheck varchar2(25 char) not null,
Adcheck varchar2(25) not null,
Blu varchar2(25) not null,
ADB varchar2(25)
)
Where one of the following is inserted (there are more entries, but one is enough to show you the way of working):
insert into control (S,N,B,Acheck,Adcheck,Blu,ADB)
values('Test','B','J','J','N','N', '');
My control file looks like:
set escape on
set serveroutput on
SET DEFINE ON
declare
cursor c_lees_control is
select S, N, B, Acheck, Adcheck, Blu, ADB
from control
v_s varchar2(30);
v_b varchar2(30);
v_blu varchar2(30);
begin
for r_lees_control in c_lees_control
loop
v_s := r_lees_control.S;
v_b := r_lees_control.B;
v_blu := r_lees_control.Blu;
if v_b = 'J' then
--Also tried this.
--@C:/Temp/uitvoer.sql $v_s $v_blu
@C:/Temp/uitvoer.sql %v_s% %v_blu%
end if;
end loop;
end;
/
In my uitvoer.sql I have a variable like this:
variable_s := '&&1';
variable_blu := '&&2';
Now the following is happening. I start SQLPlus (with all my credentials) and I start my control file (control.sql). In the output of SQLPlus the following is stated:
old 89: s = '&&1';
new 89: s = '%v_s%';
old 128: b_lu := '&&2';
new 128: b_lu := '%v_blu%';
I was expecting the following:
old 89: s = '&&1';
new 89: s = 'Test';
old 128: b_lu := '&&2';
new 128: b_lu := 'J';
Why are my variables in the control file not parsed correctly to the new SQL file?
I also found the following posts: How do you pass an argument to a PL/SQL block within a sql file called using START in sqlplus? / Launch PL/SQL script from batch file (with arguments) It looks like my challenge, but I am not calling from an batchfile but from an sql file.
I hope someone can help me. If something is unclear, I can try to explain it a bit more.
'%v_s%'and (in Nicholas' version)'v_s'? You also can't call an external file from PL/SQL; the contents ofuitvoer.sqlare being parsed as part of the block, sov_sis going to be treated as a variable in the included code - you don't need to treat it as a substitution variable at all?