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 VARCHAR2) IS
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