Table before solve:
ID NAME DATA
1 zhang 9 1 zhang 12 2 wang 1 2 wang 2/this is the table before solved/
Table after solve:
ID NAME DATA
1 DIY 13 2 DIY 3/this is what I want to get result/
There is the procedure:update A a set a.date=(select max(f_get(f.id,f.date,g.date)) from A f,A g where f.date!=g.date and f.id=a.id); --function f_get() create or replace function f_get (id in varchar2,date in varchar,date2 in varchar ) return varchar is Result varchar date3 varchar(4); begin select nvl(date,date2) into date3 from dual; Result:=date3; delete from A a where a.ID=id and a.date=date2;--there is error return(Result); end f_get;
Your question does its best to hide itself, but this is the point:
The error you get is (presumably)
ORA-14551: cannot perform a DML operation inside a query, which you are getting because you are calling a FUNCTION which includes a DELETE command from a SELECT statement.Oracle’s transactional model doesn’t allow queries to change the state of the database. Instead of a FUNCTION you need to write a procedure.
Although, if you want to remove duplicate rows, a straight SQL solution will suffice. Something like