程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> SyBase數據庫 >> SyBase綜合文章 >> SYBASE 數據庫遷移到AS 400 db2的FAQ(四)

SYBASE 數據庫遷移到AS 400 db2的FAQ(四)

編輯:SyBase綜合文章
31.Db2的循環控制語句loop用法?

答:loop例子:

OPEN c1;

SET at_end = 0;

SET numrec = 0;

fetch_loop: 1

LOOP

FETCH c1 INTO proc_cusnbr, proc_cuscrd;

IF SQLCODE = 0 THEN

SET proc_cuscrd = proc_cuscrd * 1.2;

UPDATE ordapplib.customer

SET cuscrd = proc_cuscrd

WHERE CURRENT OF c1;

SET numrec = numrec + 1;

ELSE

LEAVE fetch_loop; 2

END IF;

END LOOP fetch_loop; 3

CLOSE c1;



32.Db2的循環控制語句while用法?

答:while 例子:

OPEN c1;

SET at_end = 0;

SET numrec = 0;

WHILE at_end = 0 DO

FETCH c1 INTO proc_cusnbr, proc_cuscrd;

IF SQLCODE = 0 THEN

SET proc_cuscrd = proc_cuscrd * 1.2;

UPDATE ordapplib.customer

SET cuscrd = proc_cuscrd

WHERE CURRENT OF c1;

SET numrec = numrec + 1;

ELSE

SET at_end = 1;

END IF;

END WHILE;

CLOSE c1;



33.Db2的循環控制語句repeat用法?

答:repeat例子

SET numrec = 0;

fetch_loop:

REPEAT

FETCH c1 INTO proc_cusnbr, proc_cuscrd;

IF SQLCODE = 0 THEN

SET proc_cuscrd = proc_cuscrd * 1.2;

UPDATE ordapplib.customer

SET cuscrd = proc_cuscrd

WHERE CURRENT OF c1;

SET numrec = numrec + 1;

END IF;

UNTIL SQLCODE <> 0

END REPEAT fetch_loop;





34.Db2的循環控制語句for用法?

答:for 例子

FOR each_record AS

cursor1 CURSOR FOR

SELECT cusnbr, cuscrd FROM ordapplib.customer

DO

UPDATE ordapplib.customer

SET cuscrd = cuscrd * 1.1

WHERE CURRENT OF cursor1;

END FOR;

34.Sybase 中循環控制Break,Continue在Db2用法?

答:在db2中 Break 轉換為leave lab, Continue 轉換為ITERATE lab

等同於GOTO語句

舉例如下:

============== leave 例子

OPEN c1;

SET at_end = 0;

SET numrec = 0;

fetch_loop: 1

LOOP

FETCH c1 INTO proc_cusnbr,
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved