implicitfor.sql

来自「Oracle 9i PL/SQL程序设计的随书源码」· SQL 代码 · 共 26 行

SQL
26
字号
REM ImplicitFOR.sql
REM Chapter 6, Oracle9i PL/SQL Programming by Scott Urman
REM This block demonstrates an implicit FOR loop.

BEGIN
  -- Begin the loop. An implicit OPEN is done here.
  FOR v_StudentData IN (SELECT id, first_name, last_name
                          FROM students
                          WHERE major = 'History') LOOP
    -- An implicit FETCH is done here, and %NOTFOUND is checked

    -- Process the fetched rows, in this case sign up each
    -- student for History 301 by inserting them into the 
    -- registered_students table. Record the first and last
    -- names in temp_table as well.
    INSERT INTO registered_students (student_id, department, course)
      VALUES (v_StudentData.ID, 'HIS', 301);

    INSERT INTO temp_table (num_col, char_col)
      VALUES (v_StudentData.ID,
              v_StudentData.first_name || ' ' || v_StudentData.last_name);
  END LOOP;
  -- Now that the loop is finished, an implicit CLOSE is done.
END;
/

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?