sql中的begin....end


Begin
...
End
之間的是一個語句塊,一般Begin...End用在  ( 相當於  {})
while
if等語句中
在T_SQL中,if/while后只能緊跟一條sql語句,如果有多條則應該用Begin..end包含起來
如:
if (@int > 9)
set @int = 1
else
set @int = 0
這里的if后面只把變量@int設為1,沒有其它的操作,所以這里可以省去begin..end
但如果有多條,如
if(@int > 9)
begin
set @int = 1
select * from tablename
end
這里就必須用begin..end
否則
select語句就永遠都會被執行一次

 

 

應用於mybatis  當有多個delete時 :

<delete id="deleteHdsqByProcessinstid">

BEGIN

delete from wfworkitem c where c.processinstid in (select b.processinstid from wfprocessinst b where b.PARENTPROCID=#processinstid#);
delete from wfactivityinst c where c.processinstid in (select b.processinstid from wfprocessinst b where b.PARENTPROCID=#processinstid#);
delete from wftransctrl e where e.processinstid in (select b.processinstid from wfprocessinst b where b.PARENTPROCID=#processinstid#);
delete from wftransition g where g.processinstid in (select b.processinstid from wfprocessinst b where b.PARENTPROCID=#processinstid#);
delete from wfwiparticipant i where i.processinstid in (select b.processinstid from wfprocessinst b where b.PARENTPROCID=#processinstid#);
delete from wfprocessinst a where a.processinstid in (select b.processinstid from wfprocessinst b where b.PARENTPROCID=#processinstid#);

delete from wfworkitem where processinstid=#processinstid#;
delete from wfactivityinst where processinstid=#processinstid#;
delete from wftransctrl where processinstid=#processinstid#;
delete from wftransition where processinstid=#processinstid#;
delete from wfwiparticipant where processinstid=#processinstid#;
delete from wfprocessinst where processinstid=#processinstid#;
END;
</delete>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM