开发者

How to call update query in procedure of oracle

开发者 https://www.devze.com 2022-12-26 06:14 出处:网络
I have one table, t1, which has fileds called userid, week and year 开发者_StackOverflow社区fields.I want to call a procedure which takes all three values as arguments and fires an update query.How ca

I have one table, t1, which has fileds called userid, week and year 开发者_StackOverflow社区fields. I want to call a procedure which takes all three values as arguments and fires an update query. How can i do it?

My update query should be like

update t1 
    set week = (value of procedure argument) 
        , year = (value of procedure argument)
 where userid=(value of procedure argument);


You can do something like this:

CREATE OR REPLACE PROCEDURE my_update_proc (w number, y number, u number) IS
BEGIN
   UPDATE t1
   SET    week = w,
          year = y
   WHERE  userid = u;
   COMMIT;
END my_update_proc;
/

Update: As @Rene has correctly pointed out, you probably do not want to have a COMMIT statement in your stored procedure. If you remove it, however, the caller must remember to commit the transaction.

0

精彩评论

暂无评论...
验证码 换一张
取 消