I am fairly new to PL/SQL so I haven't been able to piece out some of the logic (specifically execute immediate)
In my PL/SQL statement, I am essentially trying to create a trigger for a prompt where the user could either have D1.SESSION or D1.A. I am using variables to create this trigger
- Wherby if
searchType = 1
then the user would input D1.SESSION data - else the user would input Input data
This trigger would be fed into a Java app. where the searchType
would be defined before running the application
The issue I am getting is when I declare the searchType as :type
, it doesn't seem to recognize the execution at the execute immediately
.
{ORA-06550: line 1, column 17:
PLS-00103: Encountered the symbol "STMT" when expecting one of the following:
:= . ( @ % ;
}
Please let me know where I am going wrong and if you provide any resources that you could point me towards the solution, that would be great!
Below is my query:
DECLARE
stmt varchar2(32767);
searchType number(3) := 1;
BEGIN
stmt := 'SELECT
D1."A" AS "A",
D1."ID" AS "ID",
D1."ID_TYPE" AS "IDTYPE",
D1."SESSION" AS "SESSION"
FROM
"DB"."TABLE" D1
WHERE (';
case
when :type = '1' then stmt := stmt || 'D1."SESSION" = (?SESSION)';
when :type = '2' then stmt := stmt || 'D1."A" in (?input)';
end case;
stmt := stmt ||')';
EXECUTE IMMEDIATE stmt using searchType;
END;
Please let me know how I can improve formating my questions on Stack. Thanks :)