plsql - Can I delete rows using user defined functions in oracle? -


i created user defined function delete data. doesn't work delete works select. oracle 9i.

the function this:

create or replace function ufn_purgedata(inputid in varchar2) return number   result number; begin    result := 0;      delete mytable mytable.id=inpid;    commit;      result := 1;  exception when others        return(result); end ufn_purgedata; 

then use select ufn_purgedata('test') dual run got result 0.

the answer question "no".

if remove error "handling" find delete failing exception like:

ora-14551: cannot perform dml operation inside query

i.e. cannot perform insert, update or delete within function called in select statement.

to execute function in ide or sql plus, wrap in more pl/sql this:

declare   l_result number; begin   l_result := my_function(123); end; 

however, need add return statement function first otherwise fail.

(nb said "handling" above in quotes because "mishandling" - disguises actual problem in unhelpful way.)


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -