I just want to define and then use a variable in Oracle SQL in SQL Developer (Version 18.1.0.095) (Background: We have some legacy production SQL script that are run periodically through jBPM).
In SQL Developer, I want to avoid the 'Enter Binds' prompt window.
Surprisingly, I found this is not that straight-forward to do. Am I missing something obvious?
CREATE TABLE Test_Persons (
PersonID int,
LastName varchar(255),
FirstName varchar(255)
);
INSERT INTO Test_Persons
(PersonID,LastName,FirstName)
values(1,'LN_1','FN_1');
INSERT INTO Test_Persons
(PersonID,LastName,FirstName)
values(2,'LN_2','FN_2');
commit;
// --- method 1: not working and shows the prompt window (which I try to avoid)--------
var last_name_input varchar2(20);
select 'LN_2' into :last_name_input from dual;
select * from Test_Persons tp where tp.LASTNAME = :last_name_input;
// --- method 2: not working and shows the prompt window (which I try to avoid) --------
declare
var last_name_input varchar2(20);
var first_name_output varchar2(20);
begin
select 'LN_2' into :last_name_input from dual;
select tp.FIRSTNAME into first_name_output from Test_Persons tp where tp.LASTNAME = :last_name_input;
-- dbms_output.Put_line('here: ' || :first_name_output);
end;
// --- method 3: working and shows the prompt window (which I try to avoid) --------
var last_name_input varchar2(20);
exec :last_name_input := 'LN_2';
select * from Test_Persons tp where tp.LASTNAME = :last_name_input;