How can I delete rows in an oracle table from xml input parameter? &gt; CREATE OR REPLACE PROCEDURE PRC_OPEN_PERIOD 
&gt;     ( InputXml in VARCHAR2,Tmode in varchar2,pOUT OUT number ) 
&gt;     IS 
&gt;      v_count NUMBER(38) := 1; 
&gt;      v_inner NUMBER(38) := 1; 
&gt;      str varchar(20); 
&gt;      l_xml xmltype;  
&gt;     BEGIN
&gt;      IF Tmode ='DELETE' THEN 
       l_xml=xmltype(InputXml);
&gt;      DELETE FROM TBL_MST_OPEN_PERIOD 
&gt;       WHERE month = l_xml.extract('//openperiod/month/text()').getStringVal() 
&gt;       and 
&gt;       village_id in (select village_id from tbl_mst_open_period 
&gt;       where 
&gt;       village_id in 
&gt;         l_xml.extract('//openperiod/village/villageID/text()').getStringVal())
&gt; ; 
&gt;      pOUT :=1;
&gt;      COMMIT;    END IF;   END;


STRUCTURE OF THE INPUT XML:

&lt;root&gt;
&lt;openperiod&gt;
&lt;month&gt;&lt;/month&gt;
&lt;village&gt;
   &lt;villageID&gt;&lt;/villageID&gt;
   &lt;villageID&gt;&lt;/villageID&gt;
&lt;/village&gt;
&lt;/openperiod&gt;
&lt;/root&gt;


I have a table named tbl_mst_open_period with columns period_id number, month number, village_id number, created_by varchar(20), is_active varchar(1).

I want to delete rows from the table by extracting the values from the xml input parameter. But the data is not getting deleted. Can anyone help??

P.S. When i replace the extarct function by hardcoded values, the delete is working. Also I tried the same xml in an insert into the table by extracting. It was working then.
Also is the delete statement actually correct??
The problem is your village subquery, it returns a single value of aggregated village ids instead of a table of ids:

SQL&gt; WITH DATA AS
  2   (SELECT XMLTYPE('&lt;root&gt;
  3  &lt;openperiod&gt;
  4  &lt;month&gt;&lt;/month&gt;
  5  &lt;village&gt;
  6     &lt;villageID&gt;1&lt;/villageID&gt;
  7     &lt;villageID&gt;2&lt;/villageID&gt;
  8  &lt;/village&gt;
  9  &lt;/openperiod&gt;
 10  &lt;/root&gt;') l_xml
 11      FROM dual)
 12  SELECT extract(l_xml,'//openperiod/village/villageID/text()').getStringVal()
 13    FROM DATA;
EXTRACT(L_XML,'//OPENPERIOD/VI
--------------------------------------------------------------------------------
12


Instead, you should use XMLTABLE (see this other SO question for example):

SQL&gt; WITH DATA AS
  2   (SELECT XMLTYPE('&lt;root&gt;
  3  &lt;openperiod&gt;
  4  &lt;month&gt;&lt;/month&gt;
  5  &lt;village&gt;
  6     &lt;villageID&gt;1&lt;/villageID&gt;
  7     &lt;villageID&gt;2&lt;/villageID&gt;
  8  &lt;/village&gt;
  9  &lt;/openperiod&gt;
 10  &lt;/root&gt;') l_xml
 11      FROM dual)
 12  SELECT x.id
 13    FROM DATA d,
 14         XMLTABLE('//openperiod/village/villageID'
 15                  PASSING d.l_xml
 16                  COLUMNS ID VARCHAR2(30) PATH 'text()') x;
ID
------------------------------
1
2


My advice when dealing with complex queries:


start with SQL, then when your query is sound and gives the good result, put it in PL/SQL
start with SELECT, not DML
decompose your query, make sure each subquery returns the appropriate result
build a small example with test tables with 1-2 rows each