ramin149
شنبه 04 آذر 1391, 11:43 صبح
با سلام .
من از فرمول حلقه که در لینک زیر آموزش داده استفاده کردم
http://www.adp-gmbh.ch/ora/plsql/loops.html
for rec in (select col_1, col_2 from table_a) loop /*Statements, use rec.col_1 and rec.col_2 */ end loop;
و باهاش دستور کدی نوشتم به صورت زیر
for rec in (select IdBlog,IdBlogSubject from tbl_BlogTag where IdBlog=@IdBlog) loop
if(SELECT Count FROM tbl_BlogSubject WHERE (IdBlogSubject = rec.IdBlogSubject)=1)
update tbl_BlogSubject set Count=0 where IdBlogSubject=rec.IdBlogSubject
else
update tbl_BlogSubject set Count=(Count-1) where IdBlogSubject=rec.IdBlogSubject
end loop;
اما خطا های زیر را پیغام می ده و نمی دونم باید چه کار کنم (چون اولین باره که می خوام for در t-sql بنویسم )
Msg 156, Level 15, State 1, Procedure BlogDelete, Line 16
Incorrect syntax near the keyword 'for'.
Msg 102, Level 15, State 1, Procedure BlogDelete, Line 16
Incorrect syntax near 'loop'.
Msg 102, Level 15, State 1, Procedure BlogDelete, Line 17
Incorrect syntax near '='.
Msg 156, Level 15, State 1, Procedure BlogDelete, Line 19
Incorrect syntax near the keyword 'else'.
Msg 102, Level 15, State 1, Procedure BlogDelete, Line 21
Incorrect syntax near 'loop'.
Msg 102, Level 15, State 1, Procedure BlogDelete, Line 24
Incorrect syntax near 'end'.
من از فرمول حلقه که در لینک زیر آموزش داده استفاده کردم
http://www.adp-gmbh.ch/ora/plsql/loops.html
for rec in (select col_1, col_2 from table_a) loop /*Statements, use rec.col_1 and rec.col_2 */ end loop;
و باهاش دستور کدی نوشتم به صورت زیر
for rec in (select IdBlog,IdBlogSubject from tbl_BlogTag where IdBlog=@IdBlog) loop
if(SELECT Count FROM tbl_BlogSubject WHERE (IdBlogSubject = rec.IdBlogSubject)=1)
update tbl_BlogSubject set Count=0 where IdBlogSubject=rec.IdBlogSubject
else
update tbl_BlogSubject set Count=(Count-1) where IdBlogSubject=rec.IdBlogSubject
end loop;
اما خطا های زیر را پیغام می ده و نمی دونم باید چه کار کنم (چون اولین باره که می خوام for در t-sql بنویسم )
Msg 156, Level 15, State 1, Procedure BlogDelete, Line 16
Incorrect syntax near the keyword 'for'.
Msg 102, Level 15, State 1, Procedure BlogDelete, Line 16
Incorrect syntax near 'loop'.
Msg 102, Level 15, State 1, Procedure BlogDelete, Line 17
Incorrect syntax near '='.
Msg 156, Level 15, State 1, Procedure BlogDelete, Line 19
Incorrect syntax near the keyword 'else'.
Msg 102, Level 15, State 1, Procedure BlogDelete, Line 21
Incorrect syntax near 'loop'.
Msg 102, Level 15, State 1, Procedure BlogDelete, Line 24
Incorrect syntax near 'end'.