You have some issues; say you have a table like
create table someTable(userName varchar2(100))
and a code like :
declare
someVariable varchar2(100);
l_entry_found number;
begin
someVariable := 'someName';
--
SELECT COUNT(*)
INTO l_entry_found
FROM someTable
WHERE username = someVariable;
end;
If you wat to switch to dynamic SQL, you need to
- remove the semicolon
- use bind variables to pass your parameter
- move the
INTO outside the dynamic part
Your code could be:
declare
someVariable varchar2(100);
l_entry_found number;
begin
someVariable := 'someName';
--
execute immediate
'SELECT COUNT(*)
FROM someTable
WHERE username = :bindVar'
into l_entry_found
using someVariable;
end;
Here I assume that you have a good reason to switch to dynamic SQL, for example, your table name could change based on some parameter; if not, plain SQL is good enough for your task.
select intoin dynamic sql;inside your SQL String.