In Oracle PL SQL, is there a way to use the variable in a subquery that was "declared"? Since all select statement requires "INTO" clause, I cant do any subqueries using the variable. All i see are people using dbms_output to print a line.
Ex:
DECLARE
name_variable varchar(20);
BEGIN
SELECT name
INTO name_variable
FROM employee
WHERE ID = 1;
Select *
FROM employee
WHERE name = name_variable;
END;
I have tried something like the above query and got something like this.
Error message when doing query like above

Also can not use the "DEFINE" as the PL SQL I am using doesnt support it.

If you want to use a
SELECTquery in PL/SQL then you cannot just useSELECT ... FROM ...and need to either:SELECT ... INTO ... FROM ...The simplest solution is to not use PL/SQL for this, just use a sub-query:
or:
Which, for the sample data:
Both output:
If you do want to use PL/SQL then use a
FORloop with an implicit cursor:Which outputs:
fiddle
Use a sub-query factoring (
WITH) clause: