---
title: "procedureTest"
author: "Forestsai"
date: "2011-06-03T17:58:59Z"
tags: []
categories: ["数据库"]
slug: "proceduretest"
draft: false
lastmod: "2011-06-03T17:58:59Z"
id: 1069779
url: "https://forestsai.iteye.com/blog/1069779"
---

--1、if  
   IF xx==1 WHEN  
     BEGIN  
      -- do something ...  
     END;  
   END IF;

--2、while  
   WHILE xx&gt;4 LOOP  
      BEGIN  
      -- do something  
      END;  
   END LOOP;

--3、for in - cursor  
   CURSOR cur IS SELECT * FROM tableName ;  
   - -  
   ...  
   IS  
   CURSOR cur IS SELECT * FROM xxtable;  
   BEGIN  
      FOR cur\_result IN cur LOOP  
        BEGIN  
            v\_sum := cur\_result.colName1 + cur\_result.colName2;  
        END;  
      END LOOP;  
   END;  
   --  
   CURSOR c\_user(c\_id NUMBER) IS SELECT NAME FROM xxtable WHERE xxx=c\_id;  
   OPEN c\_user(变量值)  
   LOOP  
      FETCH c\_user INTO v\_name;  
      EXIT FETCH c\_user%NOTFOUND;  
      --dosomething ...  
   END LOOP;

--4、select ... into...  
   BEGIN  
     SELECT col1,col2 INTO xx1,xx2 FROM xxtable WHERE xxx ;  
   EXCEPTION  
   WHEN no\_data\_found THEN  
        xxx  
   END;  
\--5、