Oracle IF 语句的结构与大多数语言类似
IF condition THEN expr; ELSIF condition THEN expr; ELSE expr; END IF;
举个例子:
SELECT COUNT(DISTINCT INDEX_NAME) INTO CNT FROM USER_INDEXES WHERE TABLE_NAME=C1.TABLE_NAME; IF CNT > 1 THEN FOR C2 IN (SELECT DISTINCT INDEX_NAME FROM USER_INDEXES WHERE TABLE_NAME=C1.TABLE_NAME) LOOP EXECUTE IMMEDIATE ‘ALTER INDEX ‘ || C2.INDEX_NAME || ‘ REBUILD‘; END LOOP; ELSIF CNT = 1 THEN EXECUTE IMMEDIATE ‘ALTER INDEX ‘ || C2.INDEX_NAME || ‘ REBUILD‘; ELSE DBMS_OUTPUT.PUT_LINE(C1.TABLE_NAME||‘ THERE IS NO INDEXES NEED TO REBUILDING‘); END IF;
本文出自 “LinuxOracle” 博客,请务必保留此出处http://onlinekof2001.blog.51cto.com/3106724/1615011
原文地址:http://onlinekof2001.blog.51cto.com/3106724/1615011