Arunfbg Arunfbg - 2 months ago 28
SQL Question

Sub query not allowed in Stored procedure error

I am trying to execute a procedure but getting an error in the below part of the procedure.

Getting the below errors:


PL/SQL: Statement ignored ERROR PLS-00405: subquery not allowed in
PLS-00405: subquery not allowed in this context
this context ERROR


The code is:

--DECLARE
L_ERROR_POINT VARCHAR2 (100);
BEGIN
P_STATUS_CODE := 0;
P_ERROR_MESSAGE := '';

--My error occurs in the below two lines--

IF(P_DE || ' A' = (SELECT DAL_ET.PARAMETER_DESC FROM DAL_ET)
AND P_IDENTIFIER_TYPE_DESCRIPTION =(SELECT DAL_ET.PARAMETER_TEXT_VALUE FROM DAL_ET))

THEN

L_ERROR_POINT := 'INSERT INTO DAL_ID_TB';


How can i rewrite this query?
Thanks in advance.

Answer

You can not use a query directly within an IF statement; to get what you need, you can use a variable:

DECLARE
  vCheckValue varchar2(100);
  ...
BEGIN
  select ...
  into vCheckValue 
  from ...
  where ...
  --
  if (vCheckValue  = ...) then
     ...
  end if;
END;