I’ve created regular function. It has been created successfully. But when I run it with
select reg('awlad','01968688680','545466455','12345') from dual
It gives me this error:
ORA-14551: cannot perform a DML operation inside a query
How can I solve this?
CREATE OR REPLACE FUNCTION reg(
name in varchar2,
cellNo in varchar2,
voterId in varchar2,
pass in varchar2
)
RETURN NUMBER
IS
succ NUMBER;
BEGIN
succ:=0;
insert into logInfo values(loginfo_seq.nextval,cellNo,pass,0);
succ:=1;
insert into passInfo values(name,cellNo,voterId);
succ:=2;
RETURN succ;
END;
A function is supposed to compute and return a result, not change the state of the database. If you want to do
DMLin a function (i.e. if you want to insert rows into tables), you cannot call that function in aSELECTstatement since aSELECTstatement cannot change the state of the database. In general, you’d be better off creating this sort of thing as a stored procedure rather than a stored function.You can call this function from a PL/SQL block just as you would call a stored procedure
If you want to create this as a procedure
then you’d need to call the procedure by passing in the
OUTparameter