waterye

Cursor FOR Loop

Implicit Cursor FOR Loop
DECLARE
    type_name 
VARCHAR2(10) := 'TABLE';
BEGIN    
    
FOR item IN (SELECT object_name, status FROM user_objects WHERE object_type = type_name) LOOP
        dbms_output.put_line(
'Table = ' || item.object_name || ', Status = ' || item.status);
    
END LOOP;
END;
/


Explicit Cursor FOR Loop
DECLARE
    
CURSOR c(type_name VARCHAR2IS
        
SELECT object_name, status FROM user_objects WHERE object_type = type_name;
    c_rec c
%ROWTYPE;
BEGIN
    
FOR item IN c('TABLE') LOOP
        dbms_output.put_line(
'Table = ' || item.object_name || ', Status = ' || item.status);
    
END LOOP;

    
OPEN c('TABLE');
    LOOP
        
FETCH c INTO c_rec;
        
EXIT WHEN c%NOTFOUND;
        dbms_output.put_line(
'Table = ' || c_rec.object_name || ', Status = ' || c_rec.status);
    
END LOOP;
    
CLOSE c;
END;
/

参考:
1. PL/SQL User's Guide and Reference
2. Java Oracle Database Development

posted on 2006-01-11 14:04 waterye 阅读(701) 评论(0)  编辑  收藏 所属分类: oracle


只有注册用户登录后才能发表评论。


网站导航: