• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

URGENT:::Can DML operation "insert" works inside a PL/SQL stored function ?

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,
I am working with PL/SQL functions .
I am trying to execute a simple "insert" statement through a PL/SQL function.
It is giving following error:
"Cannot perform DML operations inside a query".
It works fine with a PL/SQL procedure.
here is a sample code:
-----------------------------------------------
create or replace procedure testQueryProc(myarg number) is
begin
testQuery(1);
end testQueryProc;
/

create or replace procedure testQuery(arg number)is
i number(2);
read_id1 number(2);
read_id2 number(2);
begin
select id1 into read_id1 from testTable where id2=99;
dbms_output.put_line('id1 value is : '||read_id1);
for i in 1..10 loop
insert into testTable values(i,i+1);
end loop;
end testQuery;
/
above code works fine .
-----------------------------------------------
but when i try below code it says above mentioned error:
-------------------------------------------
create or replace function testQueryFunc(myarg number) return number as
begin
testQuery(1);
return 1;
end testQueryFunc;
/
create or replace procedure testQuery(arg number)is
i number(2);
read_id1 number(2);
read_id2 number(2);
begin
select id1 into read_id1 from testTable where id2=99;
dbms_output.put_line('id1 value is : '||read_id1);
for i in 1..10 loop
insert into testTable values(i,i+1);
end loop;
end testQuery;
/
-----------------------------------------------
please clarify .
Thanks ,
Srikanth
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic