Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to loop inside an UPDATE statement. Is it possible to do so? Its is giving me an error in "rec" variable. If not can you show me how I can do it. This is my code where I try to do a SELECT in order to update all the rows with all the variables.

         BEGIN
            UPDATE DATMCCN0
                SET E_NOME = (
                FOR rec IN(SELECT IID FROM DATMCCN0)
                LOOP
                SELECT I_NOME FROM DAT_CCNCONFIG0 INNER 
JOIN DATMCCN0 ON DAT_CCNCONFIG0.I_NOME = DATMCCN0.CAPLIC 
    where DATMCCN0.IID = rec.IID) 
                END LOOP;
            END;
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
149 views
Welcome To Ask or Share your Answers For Others

1 Answer

You are probably trying to do a correlated update.

UPDATE datmccn0 ccn 
SET    e_nome = (SELECT i_nome 
                 FROM   dat_ccnconfig0 conf 
                 WHERE  ccn.i_nome = conf.caplic 
                        AND ccn.iid = conf.iid); 

This statement should solve your problem.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...