agiro
agiro

Reputation: 2080

Insert into tables with & operator

I have some tables and I want to insert into them by asking their name, then putting in the values for the columns. Thing is, Whenever I run this, it goes through all the inputs no matter what, even if I input an incorrect tables. Then I get an error that it expected = symbol instead of :=. The code:

set serveroutput on;

declare
myTable varchar2;
begin
myTable = &input_table;
if myTable = 'Supervisor' then
insert into Supervisor values(&supID, &supName);
elsif myTable = 'Job' then
insert into Job values(&jobID, &jobName);
else dbms_output.put_line('Found no such table.');
end if;
end;
/

Upvotes: 0

Views: 194

Answers (1)

Dmitriy
Dmitriy

Reputation: 5565

PL/SQL scripts (running in SQLPlus or SQLPlus emulators) are not interactive tools. When you run the script, Oracle first parses its text, then defines all &-variables, then ask you to fill them, and only then begins execution. Use any interactive tools instead (in fact, for your own task you have to write your own tool yourself).

Upvotes: 1

Related Questions