只要用open语句打开的,就需要用close显示关闭

解决方案 »

  1.   

    要是我不打开直接用呢?
    那ORACLE就能负责打开和关闭?
      

  2.   

    In most situations that require an explicit cursor, you can simplify coding by using a cursor FOR loop instead of the OPEN, FETCH, and CLOSE statements
    for循环中不需要
      

  3.   

    给你个例子
    DECLARE
       result temp.col1%TYPE;
       CURSOR c1 IS
          SELECT n1, n2, n3 FROM data_table WHERE exper_num = 1;
    BEGIN
       FOR c1_rec IN c1 LOOP
          /* calculate and store the results */
          result := c1_rec.n2 / (c1_rec.n1 + c1_rec.n3);
          INSERT INTO temp VALUES (result, NULL, NULL);
       END LOOP;
       COMMIT;
    END;
      

  4.   

    用于FOR循环的游标按照正常的声明方式声明,它的优点在于不需要显式的打开、关闭、取数据,测试数据的存在、定义存放数据的变量等等
    。游标FOR 循环的语法如下:FOR record_name IN
    (corsor_name[(parameter[,parameter]...)]
    | (query_difinition)
    LOOP
    statements
    END LOOP;
      

  5.   

    DECLARE
        v_name varchar2(20);
        cursor c is select a.user_name from user a;
    BEGIN
        open c;
        loop
            fetch c into v_name ;
            exit when c%notfound;
            insert into table(id,name) values(seq_name.nextval,v_name);
        end loop;
        commit;
        close c;
    END;