oracle 有关for的疑问

superfishmanweb 2005-09-19 03:49:20
(1)for 1..10与for 1...10有什么区别?
(2)1..10是升序,那降序又如何写?
(3)步长应该如何设定
...全文
105 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
superfishmanweb 2005-09-20
  • 打赏
  • 举报
回复
THX
CodeMagic 2005-09-19
  • 打赏
  • 举报
回复
Question 1:
没见过1...10这种写法。


Question 3:

Some languages provide a STEP clause, which lets you specify a different increment
(5 instead of 1 for example). PL/SQL has no such structure, but you can easily build
one. Inside the FOR loop, simply multiply each reference to the loop counter by the
new increment. In the following example, you assign today’s date to elements 5, 10,
and 15 of an index-by table:

DECLARE
TYPE DateList IS TABLE OF DATE INDEX BY BINARY_INTEGER;
dates DateList;
k CONSTANT INTEGER := 5; -- set new increment
BEGIN
FOR j IN 1..3 LOOP
dates(j*k) := SYSDATE; -- multiply loop counter by increment
END LOOP;
...
END;
waterfirer 2005-09-19
  • 打赏
  • 举报
回复
个人认为是误导 :)
superfishmanweb 2005-09-19
  • 打赏
  • 举报
回复
哦~~~,学习了.那在plsql中的1...10中的3点是怎么回事呢?
bobfang 2005-09-19
  • 打赏
  • 举报
回复
--递减循环
for i in reverse 1..100
loop
null;
end loop;
superfishmanweb 2005-09-19
  • 打赏
  • 举报
回复
但为什么在plsql中能使用1...10(虽然结果是跳过,但没有出错).
sasacat 2005-09-19
  • 打赏
  • 举报
回复
没有降序,只能1..10,不能1...10或10..1

关于步长可以这样处理,没有设置的地方的
FOR loop_index IN 1 .. 100
LOOP
IF MOD (loop_index, 2) = 0
THEN
/* We have an even number, so perform calculation */
calc_values (loop_index);
END IF;
END LOOP;

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧